|
Cachemere
Modular Caching Library for C++
|
Least Recently Used (LRU) eviction policy. More...
#include <eviction_lru.h>
Classes | |
| class | VictimIterator |
| Iterator for iterating over cache items in the order they should be evicted. More... | |
Public Types | |
| using | CacheItem = cachemere::Item< Value > |
Public Member Functions | |
| void | clear () |
| Clears the policy. | |
| void | on_insert (const Key &key, const CacheItem &item) |
| Insertion event handler. More... | |
| void | on_update (const Key &key, const CacheItem &old_item, const CacheItem &new_item) |
| Update event handler. More... | |
| void | on_cache_hit (const Key &key, const CacheItem &item) |
| Cache hit event handler. More... | |
| void | on_evict (const Key &key, const CacheItem &item) |
| Eviction event handler. More... | |
| VictimIterator | victim_begin () const |
| Get an iterator to the first item that should be evicted. More... | |
| VictimIterator | victim_end () const |
| Get an end iterator. More... | |
Least Recently Used (LRU) eviction policy.
Implemented internally using a linked list. The keys are ordered from most-recently used to least-recently used. Only stores references to keys kept alive by the 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. |
| void cachemere::policy::EvictionLRU< Key, KeyHash, Value >::on_cache_hit | ( | const Key & | key, |
| const CacheItem & | item | ||
| ) |
Cache hit event handler.
Moves the provided item at the front of the list.
| key | The key that has been hit. |
| item | The item that has been hit. |
| void cachemere::policy::EvictionLRU< Key, KeyHash, Value >::on_evict | ( | const Key & | key, |
| const CacheItem & | item | ||
| ) |
Eviction event handler.
Removes the item at the back of the list - ensuring it has the provided key.
| key | The key that was evicted. |
| item | The item that was evicted. |
| void cachemere::policy::EvictionLRU< Key, KeyHash, Value >::on_insert | ( | const Key & | key, |
| const CacheItem & | item | ||
| ) |
Insertion event handler.
Inserts the provided item at the front of the list.
| key | The key of the inserted item. |
| item | The item that has been inserted in cache. |
| void cachemere::policy::EvictionLRU< Key, KeyHash, Value >::on_update | ( | const Key & | key, |
| const CacheItem & | old_item, | ||
| const CacheItem & | new_item | ||
| ) |
Update event handler.
Moves the provided item to the front of the list.
| key | The key that has been updated in the cache. |
| old_item | The old value for this key. |
| new_item | The new value for this key |
| auto cachemere::policy::EvictionLRU< Key, KeyHash, Value >::victim_begin |
Get an iterator to the first item that should be evicted.
Considering that the keys are ordered internally from most-recently used to least-recently used, this iterator will effectively walk the internal structure backwards.
| auto cachemere::policy::EvictionLRU< Key, KeyHash, Value >::victim_end |
Get an end iterator.
1.8.17