ExpiringCache

Data cache class template with element life time limitation. Stores items of raw data, either of fixed or dynamic size. When the life time of an item, which is the difference between its creation time and the current wall clock time, has expired, it is removed automatically on the next getRaw()/exists() access.

Constructors

this
this(size_t max_items, time_t lifetime, time_t empty_lifetime)

Constructor.

Members

Functions

exists
bool exists(hash_t key, bool expired)

Checks whether an item exists in the cache and updates its access time. If the life time of the item has expired, it is removed.

exists
bool exists(hash_t key)

Checks whether an item exists in the cache and updates its access time. If the life time of the item has expired, it is removed.

getOrCreateRaw
ValueRef getOrCreateRaw(hash_t key, bool existed)

Gets an item from the cache or creates it if not already existing. If the item was found in the cache, its access time is updated, otherwise its create time is set. If the item was found but was expired, the effect is the same as if the item was not found.

getRaw
ValueRef getRaw(hash_t key)

Gets an item from the cache. If the item was found in the cache, its access time is updated. If the item life time has expired, it is automatically removed.

getRaw
ValueRef getRaw(hash_t key, bool expired)

Gets an item from the cache. If the item was found in the cache, its access time is updated. If the item life time has expired, it is automatically removed.

num_expired
uint num_expired()
resetStats
void resetStats()

Resets the statistics counter values.

Variables

empty_lifetime
time_t empty_lifetime;

Life time for empty items in seconds; may be changed at any time. This value must be at least 1. Can be same as lifetime.

lifetime
time_t lifetime;

Life time for non-empty items in seconds; may be changed at any time. This value must be at least 1.

n_expired
uint n_expired;

Counts the number of lookups where an existing element was expired.

Inherited Members

From IExpiringCacheInfo

num_expired
uint num_expired()

Parameters

ValueSize

size of a data item. If 0 is specified (the default), the items stored in the cache are of variable (dynamic) size

Meta