Cachemere
Modular Caching Library for C++
|
1 #ifndef CACHEMERE_EVICTION_SEGMENTED_LRU_H
2 #define CACHEMERE_EVICTION_SEGMENTED_LRU_H
6 #include <absl/container/flat_hash_map.h>
8 #include "cachemere/item.h"
10 namespace cachemere::policy {
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;
39 VictimIterator(
const KeyRefReverseIt& probation_iterator,
const KeyRefReverseIt& probation_end_iterator,
const KeyRefReverseIt& protected_iterator);
41 const Key& operator*()
const;
48 KeyRefReverseIt m_probation_iterator;
49 KeyRefReverseIt m_probation_end_iterator;
50 KeyRefReverseIt m_protected_iterator;
51 bool m_done_with_probation;
102 size_t m_protected_segment_size;
104 std::list<KeyRef> m_probation_list;
105 KeyRefMap m_probation_nodes;
107 std::list<KeyRef> m_protected_list;
108 KeyRefMap m_protected_nodes;
110 bool move_to_protected(
const Key& key);
111 bool pop_to_probation();
116 #include "eviction_segmented_lru.hpp"
void on_insert(const Key &key, const CacheItem &item)
Insertion event handler.
Definition: eviction_segmented_lru.hpp:63
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_segmented_lru.hpp:72
void clear()
Clears the policy.
Definition: eviction_segmented_lru.hpp:49
void set_protected_segment_size(size_t size)
Set the maximum number of items in the protected LRU segment.
Definition: eviction_segmented_lru.hpp:58
void on_cache_hit(const Key &key, const CacheItem &item)
Cache hit event handler.
Definition: eviction_segmented_lru.hpp:77
VictimIterator victim_end() const
Get an end iterator.
Definition: eviction_segmented_lru.hpp:125
Iterator for iterating over cache items in the order they should be.
Definition: eviction_segmented_lru.h:34
VictimIterator victim_begin() const
Get an iterator to the first item that should be evicted.
Definition: eviction_segmented_lru.hpp:120
Segmented Least Recently Used (S-LRU) Eviction Policy.
Definition: eviction_segmented_lru.h:22
void on_evict(const Key &key, const CacheItem &item)
Eviction event handler.
Definition: eviction_segmented_lru.hpp:104