ICache

Constructors

this
this(size_t max_items)

Constructor.

Members

Aliases

TimeToIndex
alias TimeToIndex = .TimeToIndex

Alias required by the subclasses.

opBinaryRight
alias opBinaryRight(istring op : "in") = opIn_r

Support for the 'in' operator

Functions

accessIndex
size_t accessIndex(TimeToIndex.Node node, time_t access_time)

Obtains the index of the cache item that corresponds to node and updates the access time. If realtime is enabled, access_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 a value of at least length returned.

accessTime
time_t accessTime(hash_t key)

Checks whether an item exists in the cache and returns the last time it was accessed.

clear
void clear()

Removes all items from the cache.

exists
bool exists(hash_t key)

Checks whether an item exists in the cache.

get_
size_t get_(hash_t key, time_t access_time)

Obtains the index of the cache item that corresponds to key and updates the access time. If realtime is enabled and key could be found, access_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.

length
size_t length()
max_length
size_t max_length()
now
time_t now()

Obtains the current time. By default this is the wall clock time in seconds. This time value is used to find the least recently updated cache item and stored as create time. A subclass may override this method to use a different time unit or clock.

num_lookups
uint num_lookups()
num_misses
uint num_misses()
opIn_r
TimeToIndex.Node** opIn_r(hash_t key)

Obtains the time-to-index node for key.

register
size_t register(hash_t key, time_t access_time)

Registers a new cache element and obtains the cache item index for it. If the cache is full, the oldest cache element is replaced. If realtime is enabled, time is expected to be at least the time value of the most recent cache element. If realtime is disabled and time is less than the time value of the most recent cache element, nothing is done and a value of at least length is returned.

remove
bool remove(hash_t key)

Removes an item from the cache.

remove_
void remove_(hash_t dst_key, TimeToIndex.Node dst_node)

Removes the cache item that corresponds to dst_key and dst_node.

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".

resetStats
void resetStats()

Resets the statistics counter values.

whenCacheItemDropped
void whenCacheItemDropped(size_t index)

Called when the oldest item is replaced in cache with a new one because cache is full. When the cache gets full, the oldest item will be replaced with the new value. Before that happens, this method will be called, having the item index passed as a argument.

whenEarlierThanOldestItem
void whenEarlierThanOldestItem(time_t now, time_t oldest)

Called when the time value returned by now() is less than the time of last access of the oldest record in the cache; may be overridden by a subclass to be notified if this happens. With the system time as external data source this can theoretically happen and is at least not a program bug so in this class assert() would be inappropriate.

Variables

key_to_node
KeyToNode key_to_node;

Mapping from key to TimeToIndex.Mapping struct (which contains a mapping from an access time to the index of an elements in this.items).

n_lookups
uint n_lookups;
n_misses
uint n_misses;

Counters for the cache lookups and misses.

time_to_index
TimeToIndex time_to_index;

Mapping from access time to the index of an item in the items array. The map is implemented with an EBTree, so that it is sorted in order of access times.

Inherited Members

From ICacheInfo

max_length
size_t max_length()
length
size_t length()
num_lookups
uint num_lookups()
num_misses
uint num_misses()
resetStats
void resetStats()

Resets the statistics counter values.

Meta