Cachemere
Modular Caching Library for C++
|
1 namespace cachemere::policy {
6 m_frequency_sketch.clear();
27 return m_gatekeeper.maybe_contains(key);
32 return estimate_count_for_key(candidate) > estimate_count_for_key(victim);
37 uint32_t sketch_estimation = m_frequency_sketch.estimate(key);
38 if (m_gatekeeper.maybe_contains(key)) {
42 return sketch_estimation;
45 template<
class Key,
class KeyHash,
class Value>
void InsertionTinyLFU<Key, KeyHash, Value>::reset()
48 m_frequency_sketch.decay();
51 template<
class Key,
class KeyHash,
class Value>
template<
class KeyType>
void InsertionTinyLFU<Key, KeyHash, Value>::touch_item(
const KeyType& key)
53 if (m_gatekeeper.maybe_contains(key)) {
54 m_frequency_sketch.add(key);
55 if (m_frequency_sketch.estimate(key) > m_frequency_sketch.cardinality()) {
59 m_gatekeeper.add(key);
void on_cache_hit(const Key &key, const CacheItem &item)
Cache hit event handler.
Definition: insertion_tinylfu.hpp:9
void clear()
Clears the policy.
Definition: insertion_tinylfu.hpp:3
A wrapper for items stored in the cache.
Definition: item.h:10
Tiny Least Frequently Used (TinyLFU) insertion policy.
Definition: insertion_tinylfu.h:21
bool should_add(const Key &key)
Determines whether a given key should be inserted into the cache.
Definition: insertion_tinylfu.hpp:25
void on_cache_miss(const KeyType &key)
Cache miss event handler.
Definition: insertion_tinylfu.hpp:14
bool should_replace(const Key &victim, const Key &candidate)
Determines whether a given victim should be replaced by a given candidate.
Definition: insertion_tinylfu.hpp:30
void set_cardinality(uint32_t cardinality)
Set the cardinality of the policy.
Definition: insertion_tinylfu.hpp:19