Cachemere
Modular Caching Library for C++
|
Count constraint. More...
#include <constraint_count.h>
Public Member Functions | |
ConstraintCount (size_t maximum_count) | |
void | clear () |
Clears the policy. | |
bool | can_add (const Key &key, const CacheItem &item) |
Determines whether an insertion candidate can be added into the cache. More... | |
bool | can_replace (const Key &key, const CacheItem &old_item, const CacheItem &new_item) |
Determines whether an item already in cache can be updated. More... | |
bool | is_satisfied () |
Returns whether the constraint is satisfied. More... | |
void | update (size_t maximum_count) |
Update the cache constraint. More... | |
void | on_insert (const Key &key, const CacheItem &item) |
Insertion event handler. More... | |
void | on_evict (const Key &key, const CacheItem &item) |
Eviction event handler. More... | |
size_t | count () const |
Get the number of items currently in the cache. More... | |
size_t | maximum_count () const |
Get the maximum number of items allowed in cache. More... | |
Count constraint.
Use this when the constraint of the cache should be the number of items in cache.
Key | The type of the keys used to identify items in the cache. |
KeyHash | The type of the hasher used to hash item keys. |
Value | The type of the values stored in the cache. |
bool cachemere::policy::ConstraintCount< K, KH, V >::can_add | ( | const Key & | key, |
const CacheItem & | item | ||
) |
Determines whether an insertion candidate can be added into the cache.
That is, whether the constraint would still be satisfied after inserting the candidate.
key | The key of the insertion candidate. |
item | The candidate item. |
bool cachemere::policy::ConstraintCount< K, KH, V >::can_replace | ( | const Key & | key, |
const CacheItem & | old_item, | ||
const CacheItem & | new_item | ||
) |
Determines whether an item already in cache can be updated.
That is, whether the key can be updated to the new value while still satisfying the constraint.
key | The key to be updated. |
old_item | The current value of the key in cache. |
new_item | The value that would replace the current value. |
size_t cachemere::policy::ConstraintCount< K, KH, V >::count |
Get the number of items currently in the cache.
bool cachemere::policy::ConstraintCount< K, KH, V >::is_satisfied |
Returns whether the constraint is satisfied.
Used by the cache after a constraint update to compute how many items should be evicted, if any.
size_t cachemere::policy::ConstraintCount< K, KH, V >::maximum_count |
Get the maximum number of items allowed in cache.
void cachemere::policy::ConstraintCount< K, KH, V >::on_evict | ( | const Key & | key, |
const CacheItem & | item | ||
) |
Eviction event handler.
Removes one from the number of items in cache.
key | The key that was evicted. |
item | The item that was evicted. |
void cachemere::policy::ConstraintCount< K, KH, V >::on_insert | ( | const Key & | key, |
const CacheItem & | item | ||
) |
Insertion event handler.
Adds one to the number of items in cache.
key | The key of the inserted item. |
item | The item that has been inserted in cache. |
void cachemere::policy::ConstraintCount< K, KH, V >::update | ( | size_t | maximum_count | ) |
Update the cache constraint.
Sets a new maximum count.
maximum_count | The new number of items in cache. |