APPX 4.1 introduces the ability to create and access a cached instance of a file in memory.
The CREATE, OPEN, SCRATCH, and IF EXIST statements have been modified to include new syntax to support this feature:
CREATE statement:
The CREATE statement can now create and open a cached instance of a file. Specifying a CACHE option other than 'NONE' causes a cached instance of a file to be created in memory and opened instead of the normal disk instance of the file. The value of the CACHE option determines how the cached instance of the file is populated.
If --- NEXT DATABASE is specified for a CREATE statement which creates a cached file, then the value of next database determines the source database for loading the cache. Otherwise the current database determines the source of the file used to load the cache.
CREATE ___ ________ SHARE? _ FAIL _ CACHE _______
(1) (2) (3) (4) (5)
(1) Application ID
(2) File Name
(3) Share Y/N?
(4) Fail Type
(5) Cache type { blank || NONE, LOAD, AUTO, NOLOAD || NO LOAD }
CACHE:
NONE - Create and open the file as a normal, non-cached file.
NO LOAD - Create and open the cached instance of the file but do not load any records into the cache file.
LOAD - Create and open the cached instance of the file and load cache file from the disk instance of file.
AUTO - (Currently same as LOAD) Create and open the cached instance of the file. Dynamically populate the cache from the disk instance of the file as records are individually read.
OPEN statement:
A parameter added to the OPEN statement allows it to open either the cached instance of a file or the disk instance of the file.
If CACHE=Y and the cached instance of the file does not exist, then the OPEN statement will fail. So, a CREATE statement must be used to create the cached instance of a file before the OPEN statement can be used to open it.
If --- NEXT DATABASE is specified in conjunction with CACHE=Y, then --- NEXT DATABASE is cleared and ignored.
OPEN ___ ________ SHARE? _ FAIL _ CACHE? _
(1) (2) (3) (4) (5)
(1) Application ID
(2) File Name
(3) Share Y/N?
(4) Fail Type
(5) Cache Y/N?
SCRATCH statement:
A parameter added to the SCRATCH statement allows it to scratch either the cached instance of a file or the disk instance of the file. If --- NEXT DATABASE is specified in conjunction with CACHE=Y, then --- NEXT DATABASE is cleared and ignored.
SCRATCH ___ ________ FAIL _ CACHE? _
(1) (2) (3) (4)
(1) Application ID
(2) File Name
(3) Fail Type
(4) Cache Y/N?
CLOSE statement:
The CLOSE statement closes the currently opened instance of a file, either disk or cache.
IF EXIST statement:
The IF EXIST statement WILL BE modified in the 2nd beta release to allow its use on either the disk or cache instance of a file.
DD Specification:
The 2nd beta release will also include a specification in the DD which will allow you to specify a CACHE option:
NONE
LOAD
AUTO
These options will have the same functionality as the CREATE statement and will eliminate the need to use a CREATE statement in those cases where a file would normally be opened as a cached file.
Notes:
1) Like memory files, there can be only a single instance of a cached file. There is no separate instance of a cached file for each database.
2) Once you have opened the cached instance of a file, all I/O which follows will reference the cached instance of the file, not the disk instance.
3) If you execute a CREATE statement with CACHE=NO LOAD, then you can load the file yourself, perhaps with a subset of the records. One possible use of this would be to effectively constrain a DLU. See example below.
4) If you rewrite, delete, or write records to the cached instance of the file, the disk instance of the file will not be updated. If the disk instance of the file changes after you create and load the cached instance of the file, the cached instance of the file will not automatically include these changes.
5) Cached files were conceived of as a performance enhancement for "read only" files which are stored as tables in databases. However, they should prove to be useful in many other applications as well!
Example:
* This code creates a cached instance of the SALESREP file and
* loads it with the "Inside" salesreps
*
* Create a cache instance of the SALESREP file
CREATE CCA SALESREP SHARE? Y FAIL 0 CACHE NOLOAD
* Open the disk instance of the file
OPEN CCA SALESREP SHARE? Y FAIL 0 CACHE? N
* Read all of the SALESREP records
BEG READ CCA SALESREP HOLD 0 KEY IS SALESREP SALESPERSON
* Add only inside salesreps to the cache instance of the file
IF CCA SALESREP INSIDE EQ Y
T OPEN CCA SALESREP SHARE? Y FAIL 0 CACHE? Y
T WRITE CCA SALESREP FAIL 0
T OPEN CCA SALESREP SHARE? Y FAIL 0 CACHE? N
*
END READ CCA SALESREP
* Close the disk instance and open the cached instance - all
* references in the process will now use the cached instance
OPEN CCA SALESREP SHARE? Y FAIL 0 CACHE? Y |