Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS > Class Template Reference

#include <SynchronizedTimedCache.h>

Inheritance diagram for Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS >:
Stroika::Foundation::Cache::TimedCache< KEY, VALUE, TRAITS >

Public Member Functions

 SynchronizedTimedCache (const Time::Duration &minimumAllowedFreshness)
 
nonvirtual Time::Duration GetMinimumAllowedFreshness () const
 
nonvirtual void SetMinimumAllowedFreshness (Time::Duration minimumAllowedFreshness)
 
nonvirtual Traversal::Iterable< CacheElement > Elements () const
 
nonvirtual optional< VALUELookup (typename Common::ArgByValueType< KEY > key, Time::TimePointSeconds *lastRefreshedAt=nullptr) const
 
nonvirtual VALUE LookupValue (typename Common::ArgByValueType< KEY > key, const function< VALUE(typename Common::ArgByValueType< KEY >)> &cacheFiller, LookupMarksDataAsRefreshed successfulLookupRefreshesAcceesFlag=LookupMarksDataAsRefreshed::eDontTreatFoundThroughLookupAsRefreshed, PurgeSpoiledDataFlagType purgeSpoiledData=PurgeSpoiledDataFlagType::eAutomaticallyPurgeSpoiledData)
 
nonvirtual void Add (typename Common::ArgByValueType< KEY > key, typename Common::ArgByValueType< VALUE > result, TimedCacheSupport::PurgeSpoiledDataFlagType purgeSpoiledData=PurgeSpoiledDataFlagType::eAutomaticallyPurgeSpoiledData)
 
nonvirtual void Remove (typename Common::ArgByValueType< KEY > key)
 
nonvirtual void clear ()
 
nonvirtual void PurgeSpoiledData ()
 

Detailed Description

template<typename KEY, typename VALUE, typename TRAITS = TimedCacheSupport::DefaultTraits<KEY, VALUE>>
class Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS >
See also
TimedCache but internally synchronized. You could use Synchronized<TimedCache>, but this is simpler to use and performs better, due to not write locking until the last minute needed (you expect a cache to mostly be read from and have writes - cache misses - expensive/slow but not slow the rest of the cache (hits).
Note
Thread-Safety Internally-Synchronized-Thread-Safety
See also
TimedCache<> - for unsynchronized implementation

Definition at line 34 of file SynchronizedTimedCache.h.

Constructor & Destructor Documentation

◆ SynchronizedTimedCache()

Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS >::SynchronizedTimedCache ( const Time::Duration minimumAllowedFreshness)
Example Usage
{
static const Time::Duration kCacheTTL_{5min}; // @todo fix when Stroika Duration bug supports constexpr this should
try {
return sCache_.LookupValue (inetAddr, [] (const InternetAddress& inetAddr) {
return DNS::kThe.ReverseLookup (inetAddr);
});
}
catch (...) {
// NOTE - to NEGATIVELY CACHE failure, you could call sCache_.Add (inetAddr, nullopt);
return nullopt; // if DNS is failing, just dont do this match, dont abandon all data collection
}
}
LRUCache implements a simple least-recently-used caching strategy, with optional hashing (of keys) to...
Definition LRUCache.h:94
nonvirtual VALUE LookupValue(typename Common::ArgByValueType< KEY > key, const function< VALUE(typename Common::ArgByValueType< KEY >)> &valueFetcher)
Definition LRUCache.inl:302
Duration is a chrono::duration<double> (=.
Definition Duration.h:96
See also
TimedCache constructor for more examples

Definition at line 13 of file SynchronizedTimedCache.inl.

Member Function Documentation

◆ GetMinimumAllowedFreshness()

◆ SetMinimumAllowedFreshness()

void Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS >::SetMinimumAllowedFreshness ( Time::Duration  minimumAllowedFreshness)

◆ Elements()

◆ Lookup()

◆ LookupValue()

auto Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS >::LookupValue ( typename Common::ArgByValueType< KEY key,
const function< VALUE(typename Common::ArgByValueType< KEY >)> &  cacheFiller,
LookupMarksDataAsRefreshed  successfulLookupRefreshesAcceesFlag = LookupMarksDataAsRefreshed::eDontTreatFoundThroughLookupAsRefreshed,
PurgeSpoiledDataFlagType  purgeSpoiledData = PurgeSpoiledDataFlagType::eAutomaticallyPurgeSpoiledData 
)
See also
TimedCache::LookupValue

Definition at line 60 of file SynchronizedTimedCache.inl.

◆ Add()

void Stroika::Foundation::Cache::SynchronizedTimedCache< KEY, VALUE, TRAITS >::Add ( typename Common::ArgByValueType< KEY key,
typename Common::ArgByValueType< VALUE result,
TimedCacheSupport::PurgeSpoiledDataFlagType  purgeSpoiledData = PurgeSpoiledDataFlagType::eAutomaticallyPurgeSpoiledData 
)
See also
TimedCache::Add

Definition at line 92 of file SynchronizedTimedCache.inl.

◆ Remove()

See also
TimedCache::Remove

Definition at line 108 of file SynchronizedTimedCache.inl.

◆ clear()

◆ PurgeSpoiledData()


The documentation for this class was generated from the following files: