Cachemere
Modular Caching Library for C++
|
1 namespace cachemere::policy {
15 return (m_memory + item.
m_total_size) <= m_maximum_memory;
26 return m_memory <= m_maximum_memory;
31 m_maximum_memory = max_memory;
41 return m_maximum_memory;
47 assert(m_memory <= m_maximum_memory);
54 assert(m_memory <= m_maximum_memory);
size_t m_value_size
The size of the item.
Definition: item.h:26
void clear()
Clears the policy.
Definition: constraint_memory.hpp:8
ConstraintMemory(size_t max_memory)
Constructor.
Definition: constraint_memory.hpp:3
void update(size_t max_memory)
Update the cache constraint.
Definition: constraint_memory.hpp:29
void on_update(const Key &key, const CacheItem &old_item, const CacheItem &new_item)
Update event handler.
Definition: constraint_memory.hpp:50
bool is_satisfied()
Returns whether the constraint is satisfied.
Definition: constraint_memory.hpp:24
A wrapper for items stored in the cache.
Definition: item.h:10
size_t memory() const
Get the amount of memory currently used by the cache.
Definition: constraint_memory.hpp:34
size_t m_key_size
The size of the key.
Definition: item.h:23
bool can_add(const Key &key, const CacheItem &item)
Determines whether an insertion candidate can be added into the cache.
Definition: constraint_memory.hpp:13
size_t maximum_memory() const
Get the maximum amount of memory that can be used by the cache.
Definition: constraint_memory.hpp:39
size_t m_total_size
The total size of the item (m_key_size + m_value_size)
Definition: item.h:28
void on_insert(const Key &key, const CacheItem &item)
Insertion event handler.
Definition: constraint_memory.hpp:44
bool can_replace(const Key &key, const CacheItem &old_item, const CacheItem &new_item)
Determines whether an item already in cache can be updated.
Definition: constraint_memory.hpp:18
void on_evict(const Key &key, const CacheItem &item)
Eviction event handler.
Definition: constraint_memory.hpp:57