PriorityCache

Stores a maximum number of items keeping only items with the highest priority.

Constructors

this
this(size_t max_items)

Constructor.

Members

Aliases

ForeachDg
alias ForeachDg = int delegate(ref hash_t key, ref T item, ref ulong priority)

The signature for the delegate to be used in a foreach loop:

Functions

clear
void clear()

Removes all items from the cache.

exists
bool exists(hash_t key)

Checks whether an item exists in the cache.

get
T* get(hash_t key, bool track_misses)

Obtains the item that corresponds a key. Returns null if the key doesn't exist.

getHighestPriorityItem
T* getHighestPriorityItem(hash_t key, ulong priority)

Returns the item with highest priority.

getLowestPriorityItem
T* getLowestPriorityItem(hash_t key, ulong priority)

Returns the item with lowest priority.

getOrCreate
T* getOrCreate(hash_t key, ulong priority, bool existed, bool tracK_get_miss)

Get an item with a given key if it already existed or creates a new item with the given priority if it didn't exist.

getPriority
T* getPriority(hash_t key, ulong priority)

Retrieves an item's priority if it exists.

getUpdateOrCreate
T* getUpdateOrCreate(hash_t key, ulong priority, bool existed, bool tracK_get_miss)

Updates the priority of an item if it already existed or creates a new item with the given priority if it didn't exist.

itemDropped
void itemDropped(hash_t key, T value)

A notifier which is fired and an item is removed from the cache.

length
size_t length()
max_length
size_t max_length()
num_lookups
uint num_lookups()
num_misses
uint num_misses()
opApply
int opApply(ForeachDg dg)

A foreach-iterator for iterating over the items in the tree.

opApplyReverse
int opApplyReverse(ForeachDg dg)

A foreach-iterator for iterating over the items in the tree.

remove
bool remove(hash_t key)

Removes an item from the cache.

resetStats
void resetStats()

Resets the statistics counter values.

updatePriority
T* updatePriority(hash_t key, ulong new_priority, bool tracK_get_miss)

Updates an existing item's priority.

whenNewAndLeastPriority
bool whenNewAndLeastPriority(ulong new_item_lowest_priority, ulong current_lowest_priority)

Called by attemptCreateNode() when the cache is full and the new item to be added has a lower priority than the already existing lowest priority item. The method decides which of the two items should be stored.

Structs

CacheItem
struct CacheItem

A wrapper around the stored item

Variables

n_lookups
uint n_lookups;
n_misses
uint n_misses;

Counters for the cache lookups and misses.

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