bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
|
An in-memory cache for DapObj (DAS, DDS, ...) objects. More...
#include <ObjMemCache.h>
Public Member Functions | |
virtual void | add (libdap::DapObj *obj, const std::string &key) |
Add an object to the cache and associate it with a key. | |
virtual void | dump (ostream &os) |
What is in the cache. | |
virtual libdap::DapObj * | get (const std::string &key) |
Get the cached pointer. | |
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(). | |
ObjMemCache (unsigned int entries_threshold, float purge_threshold) | |
Initialize the DapObj cache to use an item count threshold. | |
virtual void | purge (float fraction) |
Purge the oldest elements. | |
virtual void | remove (const std::string &key) |
Remove the object associated with a key. | |
virtual unsigned int | size () const |
How many items are in the cache. | |
Friends | |
class | DDSMemCacheTest |
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.
Definition at line 83 of file ObjMemCache.h.
|
inline |
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().
Definition at line 125 of file ObjMemCache.h.
|
inline |
Initialize the DapObj cache to use an item count threshold.
The purge() method will be automatically run whenever the threshold value is exceeded and add() is called.
entries_threshold | Purge the cache when this number of items are exceeded. |
purge_threshold | When purging items, remove this fraction of the LRU items (e.g., 0.2 --> the oldest 20% items are removed) |
Definition at line 137 of file ObjMemCache.h.
|
virtual |
Definition at line 44 of file ObjMemCache.cc.
|
virtual |
Add an object to the cache and associate it with a key.
Add the pointer to the cache, purging the cache of the least recently used items if the cache was initialized with a specific threshold value. If not, the caller must take care of calling the purge() method.
obj | Pointer to be cached; caller must copy the object if caching a copy of an object is desired |
key | Associate this key with the cached object |
Definition at line 63 of file ObjMemCache.cc.
|
inlinevirtual |
What is in the cache.
os | Dump info to this stream |
Definition at line 165 of file ObjMemCache.h.
|
virtual |
|
virtual |
Purge the oldest elements.
fraction | (default is 0.2) |
Definition at line 145 of file ObjMemCache.cc.
|
virtual |
Remove the object associated with a key.
key |
Definition at line 85 of file ObjMemCache.cc.
|
inlinevirtual |
How many items are in the cache.
Definition at line 154 of file ObjMemCache.h.
|
friend |
Definition at line 114 of file ObjMemCache.h.