Using the Cache Manager
The cache manager is represented by the base class RWDBCacheManager. Rogue Wave provides an implementation of the cache manager as an in-memory object. The Rogue Wave implementation is represented by the class RWDBInMemoryCacheManager. You can create your own cache manager by deriving from RWDBCacheManager.
There is no cache manager installed by default. You must explicitly set one on an RWDBDatabase instance. The methods that cache metadata check for a cache manager and, if none is found, make no attempt to use the cache.
To use the Rogue Wave in-memory cache manager, set the cache manager in an RWDBDatabase instance:
 
RWDBDatabase db = RWDBManager::database(…); //1
RWDBInMemoryCacheManager cm; //2
RWDBCacheManager* prevCM = db.cacheManager(&cm); //3
 
...
 
db.cacheManager(prevCM); //4
//1 Create an RWDBDatabase instance.
//2 Create a cache manager, in this case the Rogue Wave-supplied in-memory cache manager.
//3 Register the cache manager with the RWDBDatabase instance. The return value is a pointer to the previous cache manager, which we save in a variable so it can be restored if necessary. If there is no previous cache manager, NULL is returned.
//4 Restore the previous cache manager. At this point, it would be safe to destroy the cm cache manager (see the discussion of the lifetime requirement below).
To use your own cache manager implementation, simply instantiate it in place of cm in the above code.
The above code installs an operational cache manager as a global object on the RWDBDatabase instance. The methods that cache metadata obtain and use this cache manager for their caching behavior. If your application creates two RWDBDatabase instances and you want caching for both, you must create two cache manager instances, one for each RWDBDatabase instance. That is, cache managers must not be shared between RWDBDatabase instances.
The fact that the cache manager is associated with a given RWDBDatabase instance has a couple of implications.
*Lifetime requirement
You must ensure that the cache manager continues to exist as long as the RWDBDatabase instance, or any object produced by the RWDBDatabase instance, exists and continues to reference it. Otherwise your application may crash or show undefined behavior.
*Thread safety
Due to its association with an RWDBDatabase instance, the cache manager is potentially accessible by multiple threads. Therefore, any function that changes the data in the cache must guarantee exclusive access to the data. The Rogue Wave methods involved in metadata caching obtain a lock on the RWDBDatabase instance before changing any data in its cache manager. If your application manipulates the cache directly, it must do the same:
 
db.acquire();
RWDBCacheManager* cm = db.cacheManager();
// do something with the cache manager
db.release();