Cache Class

The Cache class contains methods used to retrieve Record<class> objects from within a process’ local memory, calling the Db.getRecord method itself if a record does not exist in the cache. The intent of cache is to provide database optimization for references to records that either are not expected to change during the life of the cache and/or process, or where database updates can randomly be visible or not within the cache without affecting the operation of the program. Only use the Cache class in processes that contain read-only references to frequently accessed tables that exhibit repeated references to the same records (e.g., CUVAR, TRN, PRODCTL, PRODFT*).

The Cache class does not use the vobj() array for data storage. This limits the implementation to force a consistent identifier structure for all procedures that reference the cache. That is, the cache identifier (referencing the same cache) cannot be a simple variable in one process and an array in another process. This implementation enhances performance.

Using a Cache object and the Cache.getRecord method does not have a significant performance impact in an M database implementation. Benchmarks produce either negligible improvements or degradation (+/- 10%), depending on the size of the cache and the structure of the identifier (i.e., array identifiers are slower than named variables, large caches are slower than small ones). However, significant performance improvements are expected on an ORACLE database. Separate caches per table seem to be more efficient (and easier to manage) than one large array of caches with the table or process name as the subscript key.

Implement the Cache class in transaction processing and long-running batches, such as accruals. Cache the Institution Variables table (CUVAR) at the driver level (call the cache object %CACHE), making it available for all processes. Use the NEW command and KILL command on the identifier to manage the scope of a cache object.

Example

The following code provides an example of how you can cache the CUVAR and TRN tables at the driver level in a cache object called %CACHE.

 

TAG(String ETC) //

type public Cache %CUVAR

type Public Cache %CACHE()

 

type RecordCUVAR cuvar = %CUVAR.getRecord("CUVAR")

type RecordTRN trn = %CACHE("TRN").getRecord("TRN",":ETC")

 

set tjd = cuvar.tjd

set conam = cuvar.conam

 

set x = trn.etc

set x = trn.pgm

quit

image\msgs.gif

Although the CUVAR table should be cached, evaluate source code for optimization through the #IF and #ELSE compiler commands in combination with compile time CUVAR lookups. This optimization can substantially reduce the amount of database IO and code that executes at run-time.

Cache is not under transaction control and may, in fact, not represent the current state of the database or any known prior state. The state of any RecordClass object within the cache is as of the instant it was loaded into the cache.


This class is available in Profile v7.0 and greater. There are future plans to make this class available in Profile v6.4 as well.

Ancestor

Reference

Descendants

None

Methods

Description

getRecord

Retrieves a single record from within a process’ local memory.