4#ifndef _Stroika_Foundation_Cache_SynchronizedLRUCache_h_
5#define _Stroika_Foundation_Cache_SynchronizedLRUCache_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
10#include <shared_mutex>
12#include "Stroika/Foundation/Cache/LRUCache.h"
38 template <
typename KEY,
typename VALUE,
typename KEY_EQUALS_COMPARER = equal_to<KEY>,
typename KEY_HASH_FUNCTION =
nullptr_t,
typename STATS_TYPE = Statistics::StatsType_DEFAULT>
46 using KeyEqualsCompareFunctionType =
typename inherited::KeyEqualsCompareFunctionType;
52 template <
typename...
ARGS>
73 bool fHoldWriteLockDuringCacheFill{
false};
91 nonvirtual StatsType
GetStats ()
const;
115 nonvirtual
void clear ();
145 mutable shared_timed_mutex fMutex_;
160 template <
typename KEY,
typename VALUE,
typename STATS_TYPE = Statistics::StatsType_DEFAULT>
161 struct SynchronizedLRUCache_NoHash {
162 template <Common::IEqualsComparer<KEY> KEY_EQUALS_COMPARER = equal_to<KEY>>
165 return SynchronizedLRUCache<KEY, VALUE, KEY_EQUALS_COMPARER, nullptr_t, STATS_TYPE>{maxCacheSize, keyComparer};
179 template <
typename KEY,
typename VALUE,
typename STATS_TYPE = Statistics::StatsType_DEFAULT,
typename DEFAULT_KEY_EQUALS_COMPARER = equal_to<KEY>>
180 struct SynchronizedLRUCache_WithHash {
181 template <
typename KEY_HASH_FUNCTION = hash<KEY>>
182 auto operator() (
size_t maxCacheSize,
size_t hastTableSize,
const KEY_HASH_FUNCTION& hashFunction = {})
const
184 Require (maxCacheSize >= hastTableSize);
185 return SynchronizedLRUCache<KEY, VALUE, DEFAULT_KEY_EQUALS_COMPARER, KEY_HASH_FUNCTION, STATS_TYPE>{
186 maxCacheSize, DEFAULT_KEY_EQUALS_COMPARER{}, hastTableSize, hashFunction};
188 template <
typename KEY_EQUALS_COMPARER,
typename KEY_HASH_FUNCTION = hash<KEY>>
189 auto operator() (
size_t maxCacheSize,
const KEY_EQUALS_COMPARER& keyComparer,
size_t hastTableSize,
190 const KEY_HASH_FUNCTION& hashFunction = {})
const
192 Require (maxCacheSize >= hastTableSize);
193 return SynchronizedLRUCache<KEY, VALUE, KEY_EQUALS_COMPARER, KEY_HASH_FUNCTION, STATS_TYPE>{maxCacheSize, keyComparer,
194 hastTableSize, hashFunction};
207#include "SynchronizedLRUCache.inl"
LRUCache implements a simple least-recently-used caching strategy, with optional hashing (of keys) to...
simple wrapper on LRUCache (with the same API) - but internally synchronized in a way that is more pe...
nonvirtual optional< VALUE > Lookup(typename Common::ArgByValueType< KEY > key) const
nonvirtual void SetMaxCacheSize(size_t maxCacheSize)
nonvirtual KEY_HASH_FUNCTION GetKeyHashFunction() const
nonvirtual Containers::Mapping< KEY, VALUE > Elements() const
nonvirtual KeyEqualsCompareFunctionType GetKeyEqualsCompareFunction() const
nonvirtual size_t GetMaxCacheSize() const
nonvirtual VALUE LookupValue(typename Common::ArgByValueType< KEY > key, const function< VALUE(typename Common::ArgByValueType< KEY >)> &valueFetcher)
nonvirtual StatsType GetStats() const
nonvirtual size_t GetHashTableSize() const
nonvirtual void Add(typename Common::ArgByValueType< KEY > key, typename Common::ArgByValueType< VALUE > value)
conditional_t<(sizeof(CHECK_T)<=2 *sizeof(void *)) and is_trivially_copyable_v< CHECK_T >, CHECK_T, const CHECK_T & > ArgByValueType
This is an alias for 'T' - but how we want to pass it on stack as formal parameter.