Why are local Schema Cache files used:
When a client initiates database activity, the Progress client reads the database schema from a database file that resides on disk. After reading the schema from disk, the client saves a copy of the database schema (called the schema cache) in its local memory pool. Depending on the size of the schema being transmitted from database to remote client system a noticeable pause may be observed.
The time taken to build this schema cache is minimal, but when connections are established across a LAN or WAN (aka: client-server), or when several clients connect to the database simultaneously, use of the "-cache" parameter can improve connection performance.
Changes that require building a new schema cache file:
- Database schema has changed,
- Schema permissions have changed, or
- The Client Major version has changed, or
- Database dump and load has been performed.
It is possible that one or more of the following errors will appear :
The file <filename> is not a valid local cache file. (823)
CRC error in -cache <filename>. The file has been corrupted. (825)
The time stamp in the database does not match the time stamp in the -cache file: <filename>. (840)
Error while reading -cache file. ret=<return-code> errno=<errno>. (844)
WARNING: The -cache <filename> parameter was used. An error occurred while attempting to read the schema cache from the named file. The schema cache will be read from the database instead. (6126)
In these cases building a new schema cache file is necessary. This task can be a burden especially if a large number of clients have to be updated.The following code enables clients to programmatically update the local cache file only when errors 823, 825, 840, 844, or 6126 are met.
/*
Code example that first attempts to connect the database using the current cache file.
if there are cache related errors it re-generates the cache file.
*/
DEFINE VARIABLE cDbName AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCsh AS CHARACTER NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE lCacheProblem AS LOGICAL NO-UNDO.
cDbName = "sports2000".
cCsh = cDbName + ".csh" .
cCsh = SEARCH(cCsh) .
IF cCsh = ? THEN ASSIGN cCsh = "".
ELSE ASSIGN cCsh = "-cache " + cCsh.
IF cCsh = "" THEN lCacheProblem = TRUE.
CONNECT VALUE(cDbName) -H hostname -S servicename -N tcp VALUE(cCsh) NO-ERROR.
IF ERROR-STATUS:NUM-MESSAGES > 1 THEN
DO i = 1 TO ERROR-STATUS:NUM-MESSAGES :
/*
Trap errors that have to do with the cache file being used for this specific connection attempt...
The errors trapped in this example are:
The file <filename> is not a valid local cache file. (823)
CRC error in -cache <filename>. The file has been corrupted. (825)
The time stamp in the database does not match the time stamp in the -cache file: <filename>. (840)
Error while reading -cache file. ret=<return-code> errno=<errno>. (844)
WARNING: The -cache <filename> parameter was used. An error occurred while attempting to read the schema cache from the named file.
The schema cache will be read from the database instead. (6126)
*/
IF ERROR-STATUS:GET-NUMBER(i) = 823 OR
ERROR-STATUS:GET-NUMBER(i) = 825 OR
ERROR-STATUS:GET-NUMBER(i) = 840 OR
ERROR-STATUS:GET-NUMBER(i) = 844 OR
ERROR-STATUS:GET-NUMBER(i) = 6126 THEN
lCacheProblem = TRUE.
/*
If none of the cache related errors where reported,
then it could be a genuine problem with connecting the database so we should log these.
*/
MESSAGE "Error " ERROR-STATUS:GET-NUMBER(i) ": " ERROR-STATUS:GET-MESSAGE(i) .
END.
IF CONNECTED(cDbName) THEN
DO:
/*
If we are connected and there was a problem with the cache file,
then we have to re-generate it ...
*/
IF lCacheProblem THEN
SAVE CACHE COMPLETE VALUE(cDbName) TO VALUE(cDbName + ".csh") .
/*
Otherwise, we are connected and there were no errors with the schema file so we don't need to generate it,
or we were already connected and received message 1012 so we have already used the -cache file that was correct,
or we are going to re-generate it on the next connection.
*/
END.
ELSE MESSAGE "Problem connecting to the database" .