16template <
typename TKey,
typename TValue>
31 [[nodiscard]]
virtual auto capacity() const -> std::
size_t = 0;
34 [[nodiscard]] virtual auto
size() const -> std::
size_t = 0;
39 virtual auto
get(const TKey& k) -> TValue = 0;
42 virtual auto
put(const TKey& k, const TValue& v) ->
void = 0;
45 virtual auto
contains(const TKey& k) ->
bool = 0;
48 virtual
void onEvict(std::function<
bool(TKey&, TValue&)> fn) = 0;
54 virtual auto
evict() ->
void = 0;
57 virtual auto
purge() ->
void = 0;
Abstract Base Class for Key-Value Caches.
virtual auto put(const TKey &k, const TValue &v) -> void=0
Put an item into the cache.
virtual auto purge() -> void=0
Evict all items ignoring cache policy.
virtual auto get(const TKey &k) -> TValue=0
Get an item from the cache by key.
std::function< bool(TKey &, TValue &)> on_eject_
virtual void resetOnEvict()=0
Remove the validation callback function.
virtual void onEvict(std::function< bool(TKey &, TValue &)> fn)=0
Callback function when items are evicted.
std::shared_ptr< Cache > Pointer
virtual auto contains(const TKey &k) -> bool=0
Check if an item is already in the cache.
virtual auto size() const -> std::size_t=0
Get the current number of elements in the cache.
virtual void setCapacity(std::size_t newCapacity)=0
Set the maximum number of elements in the cache.
virtual auto evict() -> void=0
Evict items following the cache policy.
virtual auto capacity() const -> std::size_t=0
Get the maximum number of elements in the cache.
Volume Cartographer library