bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
|
A simple memory cache. More...
#include <MemoryCache.h>
Public Member Functions | |
virtual void | clear () |
Clear the cache. | |
virtual bool | get (const std::string &key, VALUE &value) |
Get the item from the cache. If the item is not in the cache, the value-result parameter is not modified. | |
virtual bool | initialize (int max_items, int purge_items) |
Initialize the cache. | |
MemoryCache (const MemoryCache *src)=delete | |
MemoryCache & | operator= (const MemoryCache *src)=delete |
virtual void | put (const std::string &key, const VALUE &value) |
Put the item in the cache. If the key is already in the cache, the value is updated. | |
virtual unsigned long | size () const |
How many items are in the cache. | |
Friends | |
class | MemoryCacheTest |
A simple memory cache.
This is a header-only class. It is used by NgapRequestHandler to cache string values. It could be tested more completely and used in other places.
The cache implements a simple FIFO queue to purge the oldest entries when the cache is full. Purging is done when the count of cached items exceeds the maximum number of items allowed in the cache. The private purge method will remove the oldest P entries from the cache where P is the number of 'purge items' as set with the initialize() method.
Instead of initializing the cache (setting the max and purge item counts) using a constructor, am initialize() method is used. The constructors never throw exceptions. If initialize() fails, it returns false. The get() and put() methods may throw exceptions.
The cache is not thread-safe.
VALUE | As of 10/17/23 only tested with std::string |
Definition at line 64 of file MemoryCache.h.
|
inlinevirtual |
Clear the cache.
Definition at line 166 of file MemoryCache.h.
|
inlinevirtual |
Get the item from the cache. If the item is not in the cache, the value-result parameter is not modified.
key | |
value | Value-result parameter; operator=() is used to copy the value of the cached item. |
Definition at line 133 of file MemoryCache.h.
|
inlinevirtual |
Initialize the cache.
max_items | Must be greater than zero |
purge_items | Must be greater than zero |
Definition at line 117 of file MemoryCache.h.
|
inlinevirtual |
Put the item in the cache. If the key is already in the cache, the value is updated.
key | |
value |
Definition at line 149 of file MemoryCache.h.
|
inlinevirtual |
How many items are in the cache.
Definition at line 163 of file MemoryCache.h.
|
friend |
Definition at line 102 of file MemoryCache.h.