Cachemere
Modular Caching Library for C++
|
1 #ifndef CACHEMERE_EVICTION_LRU
2 #define CACHEMERE_EVICTION_LRU
9 #include <absl/container/flat_hash_map.h>
11 #include "cachemere/item.h"
13 namespace cachemere::policy {
22 template<
typename Key,
typename KeyHash,
typename Value>
class EvictionLRU
25 using KeyRef = std::reference_wrapper<const Key>;
26 using KeyRefIt =
typename std::list<KeyRef>::iterator;
27 using KeyRefMap = absl::flat_hash_map<KeyRef, KeyRefIt, KeyHash, std::equal_to<Key>>;
37 using KeyRefReverseIt =
typename std::list<KeyRef>::const_reverse_iterator;
41 const Key& operator*()
const;
48 KeyRefReverseIt m_iterator;
91 std::list<KeyRef> m_keys;
97 #include "eviction_lru.hpp"
void on_insert(const Key &key, const CacheItem &item)
Insertion event handler.
Definition: eviction_lru.hpp:40
void on_cache_hit(const Key &key, const CacheItem &item)
Cache hit event handler.
Definition: eviction_lru.hpp:54
Iterator for iterating over cache items in the order they should be evicted.
Definition: eviction_lru.h:34
void clear()
Clears the policy.
Definition: eviction_lru.hpp:34
A wrapper for items stored in the cache.
Definition: item.h:10
void on_update(const Key &key, const CacheItem &old_item, const CacheItem &new_item)
Update event handler.
Definition: eviction_lru.hpp:49
VictimIterator victim_begin() const
Get an iterator to the first item that should be evicted.
Definition: eviction_lru.hpp:83
Least Recently Used (LRU) eviction policy.
Definition: eviction_lru.h:22
VictimIterator victim_end() const
Get an end iterator.
Definition: eviction_lru.hpp:88
void on_evict(const Key &key, const CacheItem &item)
Eviction event handler.
Definition: eviction_lru.hpp:68