Cache

Data cache class template. Stores items of raw data, either of fixed or dynamic size.

Constructors

this
this(size_t max_items)

Constructor.

Members

Functions

access
CacheItem* access(TimeToIndex.Node node, time_t access_time)

Obtains the cache item that corresponds to node and updates the access time. If realtime is enabled, time is expected to be equal to or greater than the time stored in node. If disabled and the access time is less, the node will not be updated and null returned.

add
CacheItem* add(hash_t key, time_t access_time)

Adds an item to the cache. If the cache is full, the oldest item will be removed and replaced with the new item.

createRaw
ValueRef createRaw(hash_t key)

Creates an item in the cache and sets its 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.)

createTime
time_t createTime(hash_t key)

Checks whether an item exists in the cache and returns its create time.

dumpTimes
void dumpTimes(char[] filename, time_t now)

Writes the access times and the number of records with that time to a file, appending to that file.

enableGcValueScanning
void enableGcValueScanning()

Makes the GC scan the cache items. Should be called by the subclass constructor if it stores values that contain GC references. This method should be called after the constructor of this class has returned.

getItem
CacheItem* getItem(size_t index)

Obtains the cache item that corresponds to index. Returns null if index is length or greater.

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.

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.

get__
CacheItem* get__(hash_t key, time_t access_time)

Obtains the cache item that corresponds to node and updates the access time. If realtime is enabled and key could be found, time is expected to be at least the time value stored in node. If disabled and access_time is less, the result is the same as if key could not be found.

keyByIndex
hash_t keyByIndex(size_t index)

Obtains the key of the cache item corresponding to index.

replaceRemovedItem
hash_t replaceRemovedItem(size_t replaced, size_t replace)

Called when a cache element is removed, replaces the cache items at index "replaced" with the one at index "replace" by swapping the items.

Mixins

__anonymous
mixin Value!(ValueSize)

Mixin the type definition for the values.

Structs

CacheItem
struct CacheItem

Cached item struct, storing a key and value.

Parameters

ValueSize

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

TrackCreateTimes

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

Meta