Cachemere
Modular Caching Library for C++
|
1 #ifndef CACHEMERE_EVICTION_GDSF
2 #define CACHEMERE_EVICTION_GDSF
6 #include <absl/container/btree_map.h>
8 #include "cachemere/item.h"
9 #include "cachemere/policy/detail/counting_bloom_filter.h"
11 namespace cachemere::policy {
24 template<
typename Key,
typename KeyHash,
typename Value,
typename Cost>
class EvictionGDSF
27 using KeyRef = std::reference_wrapper<const Key>;
29 struct PriorityEntry {
30 PriorityEntry(KeyRef key,
double coefficient);
32 bool operator<(
const PriorityEntry& other)
const;
35 double m_h_coefficient;
38 using PrioritySet = std::multiset<PriorityEntry>;
39 using PrioritySetIt =
typename PrioritySet::const_iterator;
51 const Key& operator*()
const;
58 PrioritySetIt m_iterator;
106 using IteratorMap = absl::btree_map<KeyRef, PrioritySetIt, std::less<const Key>>;
108 const static uint32_t DEFAULT_CACHE_CARDINALITY = 2000;
109 mutable Cost m_measure_cost;
112 PrioritySet m_priority_set;
114 IteratorMap m_iterator_map;
119 [[nodiscard]]
double get_h_coefficient(
const Key& key,
const CacheItem& item)
const noexcept;
124 #include "eviction_gdsf.hpp"
void on_cache_hit(const Key &key, const CacheItem &item)
Cache hit event handler.
Definition: eviction_gdsf.hpp:74
void on_evict(const Key &key, const CacheItem &item)
Eviction event handler.
Definition: eviction_gdsf.hpp:86
void set_cardinality(uint32_t cardinality)
Set the cardinality of the policy.
Definition: eviction_gdsf.hpp:55
void on_insert(const Key &key, const CacheItem &item)
Insertion event handler.
Definition: eviction_gdsf.hpp:60
A wrapper for items stored in the cache.
Definition: item.h:10
VictimIterator victim_end() const
Get an end iterator.
Definition: eviction_gdsf.hpp:105
Greedy-Dual-Size-Frequency (GDSF) eviction policy.
Definition: eviction_gdsf.h:24
void clear()
Clears the policy.
Definition: eviction_gdsf.hpp:48
VictimIterator victim_begin() const
Get an iterator to the first item that should be evicted.
Definition: eviction_gdsf.hpp:100
Iterator for iterating over cache items in the order they should be evicted.
Definition: eviction_gdsf.h:46
void on_update(const Key &key, const CacheItem &old_item, const CacheItem &new_item)
Update event handler.
Definition: eviction_gdsf.hpp:69