Stroika Library 3.0d23
 
Loading...
Searching...
No Matches
Stroika::Foundation::Cache Namespace Reference

Namespaces

namespace  LRUCacheSupport
 
namespace  TimedCacheSupport
 

Classes

class  BloomFilter
 a Bloom filter is a probablistic set, which returns either "probably in set" or "definitely not in set" More...
 
class  LRUCache
 LRUCache implements a simple least-recently-used caching strategy, with optional hashing (of keys) to make it faster. More...
 
class  Memoizer
 Cache the results of expensive computations transparently. More...
 
class  TimedCache
 Keep track of a bunch of objects, each with an associated time used to allow data to 'expire'. More...
 

Concepts

concept  IKey
 A KEY is any copyable value (or the sentinal type void - indicating a keyless - single valued - cache)
 
concept  IValue
 any copyable type can use used as the value, or the special sentinal type - ValuelessSentinalType, used to indicate we are just caching presence/absense of the KEY in the cache (and its expiration date).
 
concept  ICache
 Check if the argument CACHE is a valid 'stroika cache' class, following its api.
 

Typedefs

using NonKeyedKeySentinalType = void
 This sentinal value can be used as the KEY type for a Cache to indicate it is un-keyed, and there is just one.
 
using ValuelessSentinalType = void
 This sentinal value can be used as the VALUE type for a Cache to indicate it just stores ONLY the KEYS (and sometimes related time/expiration) information.
 
template<typename KEY , typename VALUE , LRUCacheSupport::ITraits< KEY, VALUE > TRAITS = LRUCacheSupport::DefaultTraits<KEY, VALUE>>
using SynchronizedLRUCache = LRUCache< KEY, VALUE, LRUCacheSupport::InternallySynchronizedTraits< TRAITS > >
 
template<typename KEY , typename VALUE , TimedCacheSupport::ITraits< KEY, VALUE > TRAITS = TimedCacheSupport::DefaultTraits<KEY, VALUE>>
using SynchronizedTimedCache = TimedCache< KEY, VALUE, TimedCacheSupport::InternallySynchronizedTraits< TRAITS > >
 SynchronizedTimedCache just adds eInternallySynchronized to a regular 'TimedCache' (just short-hand).
 

Variables

template<typename KEY >
static constexpr bool IKeyedCache = not same_as<KEY, NonKeyedKeySentinalType>
 does this cache have a KEY type (overwhelming YES, but sometimes handy to have 'singleton' cache, where you cache something, but just one of them)
 
template<typename VALUE >
static constexpr bool IValuelessCache = same_as<VALUE, ValuelessSentinalType>
 Some caches (rare) only support a KEY, with no associated value (the value is stored INSIDE the key itself)
 

Detailed Description

Note
Code-Status: Beta
 \file
Note
Code-Status: Beta

TODO:

Also somewhat related, _Last usage is C++ unconvnetional - though maybe OK. If not more awkward in impl, consider using _fEnd? Or if it is (I think last maybe better then document clearly why its better.

Note
Code-Status: Beta

TODO:

 \file
Note
Code-Status: Beta

TODO:

AND RELATED cleanup to spec using InOrderComparerType - as opposed to EQUALS COMPARER or other stuff like HashFunctions! MAYBE LOSE inorder comparer arg - and INSTEAD have template / template for creating container (for now its map<>??)

Implementation Note:

This module uses stl:map<> instead of a Stroika Mapping since we are comfortable with
the current implementation using btree's, and to avoid any dependencies between
Caching and Containers. We may want to re-think that, and just  use Mapping here.

Typedef Documentation

◆ ValuelessSentinalType

This sentinal value can be used as the VALUE type for a Cache to indicate it just stores ONLY the KEYS (and sometimes related time/expiration) information.

Also, this can be used like KeyedCollection - where the main object acts like a KEY and value at the same time (often just internally has a KEY field).

Definition at line 45 of file Foundation/Cache/Common.h.

◆ SynchronizedLRUCache

template<typename KEY , typename VALUE , LRUCacheSupport::ITraits< KEY, VALUE > TRAITS = LRUCacheSupport::DefaultTraits<KEY, VALUE>>
using Stroika::Foundation::Cache::SynchronizedLRUCache = typedef LRUCache<KEY, VALUE, LRUCacheSupport::InternallySynchronizedTraits<TRAITS> >

DEPRECATED CLASS TEMPLATES

Definition at line 494 of file LRUCache.inl.

◆ SynchronizedTimedCache

template<typename KEY , typename VALUE , TimedCacheSupport::ITraits< KEY, VALUE > TRAITS = TimedCacheSupport::DefaultTraits<KEY, VALUE>>
using Stroika::Foundation::Cache::SynchronizedTimedCache = typedef TimedCache<KEY, VALUE, TimedCacheSupport::InternallySynchronizedTraits<TRAITS> >

SynchronizedTimedCache just adds eInternallySynchronized to a regular 'TimedCache' (just short-hand).

Template Parameters
KEY
VALUE
TRAITS
Example Usage
Use TimedCache to avoid needlessly redundant lookups
optional<String> ReverseDNSLookup_ (const InternetAddress& inetAddr)
{
// Or could write like this
return sCache_.LookupValue (inetAddr, [] (const InternetAddress& inetAddr) {
return DNS::kThe.ReverseLookup (inetAddr);
});
}
Keep track of a bunch of objects, each with an associated time used to allow data to 'expire'.
Definition TimedCache.h:572
nonvirtual VALUE LookupValue(typename Common::ArgByValueType< K > key, CACHE_FILLTER_T &&cacheFiller)
Lookup value, and if missing, fetch it with argument cacheFiller (and add/return its value).
InternallySynchronizedTraits same as argument traits, but resetting the kInternallySynchronized to eI...
Definition TimedCache.h:284
Note
this CAN be done pretty easily without defining SynchronizedTimedCache (e.g. InternallySynchronizedTraits), but this is enough more terse and common enough to be useful.

Definition at line 1171 of file TimedCache.h.

Variable Documentation

◆ IValuelessCache

template<typename VALUE >
constexpr bool Stroika::Foundation::Cache::IValuelessCache = same_as<VALUE, ValuelessSentinalType>
staticconstexpr

Some caches (rare) only support a KEY, with no associated value (the value is stored INSIDE the key itself)

Example Usage:

Definition at line 61 of file Foundation/Cache/Common.h.