Cache

Typed cache class template. Stores items of a particular type.

Constructors

this
this(size_t max_items)

Constructor.

Members

Functions

create
T* create(hash_t key)

Creates a cache item and sets the create time. If the cache is full, the oldest item is replaced with the new item. (In the case where several items are equally old, the choice of which one to be replaced is made arbitrarily.)

get
T* get(hash_t key)

Gets an item from the cache. A pointer to the item is returned, if found. If the item exists in the cache, its update time is updated.

getOrCreate
T* getOrCreate(hash_t key, bool existed)

Gets an item from the cache or creates it if not already existing. If the item exists in the cache, its update time is updated, otherwise its create time is set.

put
bool put(hash_t key, T value)

Puts an item into the cache. If the cache is full, the oldest item is replaced with the new item. (In the case where several items are equally old, the choice of which one to be replaced is made arbitrarily.)

Parameters

T

type of item to store in cache

TrackCreateTimes

if true, each cache item is stored with its create time, in addition to its last access time

Meta