Infrasctucture Cache Function Reference
Cache
#include "cache.h"

The cache layer is used to save information to disk so that it is non-volatile across process or system crashes or reboots.   In other words, if a piece of data or a request absolutely HAS to get there, you better cache it.   Data may be added (cached) or deleted (uncached) randomly or read sequentially as a process starts up (restore).   Cache handles are integers in the range of 1 to 1*231, values less than 1 are used as error returns.   Each record in the cache has an 'id' (identifier), supplied by the user, which is used to find the record (like a key).   Caveat: The cache layer doesn't check to be sure the ID is unique.   Cached records may be variable in size.

cchCln cchOpn cchRd cchRew
cchUnch cchWt

int cchCln( int cHndl )
Compress the cache file. Returns zero.


int cchOpn( char* fileName )
Opens a cache file for reading or writing.
On success it returns an integer cache handle required by all other cache API calls.
On error it returns ERR (-1).
BTW: The clean process creates a backup of the pre-cleaned file named oldFileName with ".BU.cch" replacing the ".cch".
In this way multiple caches may be maintained by one process.


int cchRd( int cHndl, char* data, int* len )
Immediately after cchOpen() or cchRew(), reads a record sequentially, from the cache file represented by cHndl.
The 'data' argument is a pointer to the data area.
The 'len' is a pointer to an integer that will be loaded with the number of bytes read.
On success it returns the 'id' of the record retrieved.
On error it returns ERR (-1).


int cchRew( int cHndl )
Rewind the cache file pointers.


int cchUnch( int cHndl, long id )
Remove a record from the cache file represented by cHndl.
If the record was the last in the file the file is truncated.
Returns zero.


int cchWt( int cHndl, char* dataP, int len, long id )
Writes a record to the cache file represented by cHndl.
The 'data' argument is a pointer to the data to be written,
'len' is the number of bytes to write and 'id' is a 32 bit record identifyer which must be used to retrieve the record.
On success it returns the number of data bytes written.
On error it returns ERR (-1).