ExpiringLRUCache

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 getAndRefreshValue()/exists() access.

Constructors

this
this(size_t max_items, time_t lifetime)

Constructor.

Members

Aliases

getAndRefresh
alias getAndRefresh = LRUCache!(T, true).getAndRefresh

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.

getRefreshOrCreate
alias getRefreshOrCreate = LRUCache!(T, true).getRefreshOrCreate

Imports the super class overloaded methods which were hidden by the getOrCreate() override implementation.

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.

getAndRefresh
T* getAndRefresh(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.

getAndRefresh
T* getAndRefresh(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.

getRefreshOrCreate
T* getRefreshOrCreate(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.

num_expired
uint num_expired()
resetStats
void resetStats()

Resets the statistics counter values.

Variables

lifetime
time_t lifetime;

Life time for all 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

T

the type of data that will be stored

Meta