|
virtual void | add (libdap::DapObj *obj, const std::string &key) |
| Add an object to the cache and associate it with a key. More...
|
|
virtual void | dump (ostream &os) |
| What is in the cache. More...
|
|
virtual libdap::DapObj * | get (const std::string &key) |
| Get the cached pointer. More...
|
|
| ObjMemCache () |
| Initialize the DapObj cache This constructor builds a cache that will require the caller manage the purge() operations. Setting the entries_threshold property to zero disables checking the cache size in add(). More...
|
|
| ObjMemCache (unsigned int entries_threshold, float purge_threshold) |
| Initialize the DapObj cache to use an item count threshold. More...
|
|
virtual void | purge (float fraction) |
| Purge the oldest elements. More...
|
|
virtual void | remove (const std::string &key) |
| Remove the object associated with a key. More...
|
|
virtual unsigned int | size () const |
| How many items are in the cache. More...
|
|
An in-memory cache for DapObj (DAS, DDS, ...) objects.
This cache stores pointers to DapObj objects in memory (not on disk) and thus, it is not a persistent cache. It provides no assurances regarding multi-process or thread safety. Thus, the cache should only be used by a single process - if there are several BES processes, each should have their own copy of the cache.
The cache stores pointers to objects, not objects themselves. The user of the cache must take care of copying objects that are added or accessed to/from the cache unless the lifetime of an pointer in the cache will suffice for the use at hand. For example, a cached DAS pointer can be passed to DDS::transfer_attributes(DAS *); there is no need to copy the underlying DAS. However, returning a DAS to the BES for serialization requires that a copy be made since the BES will delete the returned object.
The cache implements a LRU purge policy, where when the purge() method is called, the oldest 20% of times are removed. When an item is accessed (add() or get()), it's access time is updated, so the LRU policy is also a low-budget frequency of use policy without actually keeping count of the total number of accesses. The size (number of items, not bytes) of the cache is examined for every add() call and purge() is called if a preset threshold is exceeded. The purge level (20% by default) can be configured.
When an object is removed from the cache using remove() or purge(), it is deleted.
- Note
- The cache uses an unsigned long long to track the age of items in the cache. It's possible that numbers could wrap around (although that would be a very long-running process) in which case the code will think that the newest objects in the cache are the oldest and remove them. After d_entries_threshold, this will even itself out and the cache will correctly purge the oldest entries.
Definition at line 84 of file ObjMemCache.h.