xrpld
Loading...
Searching...
No Matches
xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex > Class Template Reference

Map/cache combination. More...

#include <TaggedCache.h>

Collaboration diagram for xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >:

Classes

struct  Stats
class  KeyOnlyEntry
class  ValueEntry

Public Types

using mutex_type = Mutex
using key_type = Key
using mapped_type = T
using clock_type = beast::AbstractClock<std::chrono::steady_clock>
using shared_weak_combo_pointer_type = SharedWeakUnionPointerType
using shared_pointer_type = SharedPointerType
using SweptPointersVector = std::vector<SharedWeakUnionPointerType>

Public Member Functions

 TaggedCache (std::string const &name, int size, clock_type::duration expiration, clock_type &clock, beast::Journal journal, beast::insight::Collector::ptr const &collector=beast::insight::NullCollector::make())
clock_typeclock ()
 Return the clock associated with the cache.
std::size_t size () const
 Returns the number of items in the container.
int getCacheSize () const
int getTrackSize () const
float getHitRate ()
void clear ()
void reset ()
template<class KeyComparable>
bool touchIfExists (KeyComparable const &key)
 Refresh the last access time on a key if present.
void sweep ()
bool del (key_type const &key, bool valid)
template<class Callback>
bool canonicalize (key_type const &key, SharedPointerType &data, Callback &&replaceCallback)
 Replace aliased objects with originals.
bool canonicalizeReplaceCache (key_type const &key, SharedPointerType const &data)
 Insert/update the canonical entry for key, always replacing the cached value with data.
bool canonicalizeReplaceClient (key_type const &key, SharedPointerType &data)
 Insert the canonical entry for key, keeping any existing cached value.
SharedPointerType fetch (key_type const &key)
template<class ReturnType = bool>
auto insert (key_type const &key, T const &value) -> std::enable_if_t<!IsKeyCache, ReturnType >
 Insert the element into the container.
template<class ReturnType = bool>
auto insert (key_type const &key) -> std::enable_if_t< IsKeyCache, ReturnType >
bool retrieve (key_type const &key, T &data)
mutex_typepeekMutex ()
std::vector< key_typegetKeys () const
double rate () const
 Returns the fraction of cache hits.
template<class Handler>
SharedPointerType fetch (key_type const &digest, Handler const &h)
 Fetch an item from the cache.

Private Types

template<typename Policy>
using CanonicalizeClientPointerType
using Entry = std::conditional_t<IsKeyCache, KeyOnlyEntry, ValueEntry>
using KeyOnlyCacheType = hardened_partitioned_hash_map<key_type, KeyOnlyEntry, Hash, KeyEqual>
using KeyValueCacheType = hardened_partitioned_hash_map<key_type, ValueEntry, Hash, KeyEqual>
using cache_type = hardened_partitioned_hash_map<key_type, Entry, Hash, KeyEqual>

Private Member Functions

template<class Policy, class Callback = std::nullptr_t>
bool canonicalizeImpl (key_type const &key, CanonicalizeClientPointerType< Policy > data, Policy policy, Callback &&replaceCallback=nullptr)
 Shared implementation of the canonicalize family.
SharedPointerType initialFetch (key_type const &key, std::scoped_lock< mutex_type > const &l)
void collectMetrics ()
std::thread sweepHelper (clock_type::time_point const &whenExpire, clock_type::time_point const &now, KeyValueCacheType::map_type &partition, SweptPointersVector &stuffToSweep, std::atomic< int > &allRemovals, std::scoped_lock< std::recursive_mutex > const &)
std::thread sweepHelper (clock_type::time_point const &whenExpire, clock_type::time_point const &now, KeyOnlyCacheType::map_type &partition, SweptPointersVector &, std::atomic< int > &allRemovals, std::scoped_lock< std::recursive_mutex > const &)

Private Attributes

beast::Journal journal_
clock_typeclock_
Stats stats_
mutex_type mutex_
std::string name_
int const targetSize_
clock_type::duration const targetAge_
int cacheCount_ {0}
cache_type cache_
std::uint64_t hits_ {0}
std::uint64_t misses_ {0}

Detailed Description

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
class xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >

Map/cache combination.

This class implements a cache and a map. The cache keeps objects alive in the map. The map allows multiple code paths that reference objects with the same tag to get the same actual object.

So long as data is in the cache, it will stay in memory. If it stays in memory even after it is ejected from the cache, the map will track it.

Note
Callers must not modify data objects that are stored in the cache unless they hold their own lock over all cache operations.

Definition at line 58 of file TaggedCache.h.

Member Typedef Documentation

◆ mutex_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::mutex_type = Mutex

Definition at line 61 of file TaggedCache.h.

◆ key_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::key_type = Key

Definition at line 62 of file TaggedCache.h.

◆ mapped_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::mapped_type = T

Definition at line 63 of file TaggedCache.h.

◆ clock_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clock_type = beast::AbstractClock<std::chrono::steady_clock>

Definition at line 64 of file TaggedCache.h.

◆ shared_weak_combo_pointer_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::shared_weak_combo_pointer_type = SharedWeakUnionPointerType

Definition at line 65 of file TaggedCache.h.

◆ shared_pointer_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::shared_pointer_type = SharedPointerType

Definition at line 66 of file TaggedCache.h.

◆ SweptPointersVector

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::SweptPointersVector = std::vector<SharedWeakUnionPointerType>

Definition at line 108 of file TaggedCache.h.

◆ CanonicalizeClientPointerType

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<typename Policy>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::CanonicalizeClientPointerType
private
Initial value:

Definition at line 121 of file TaggedCache.h.

◆ Entry

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::Entry = std::conditional_t<IsKeyCache, KeyOnlyEntry, ValueEntry>
private

Definition at line 329 of file TaggedCache.h.

◆ KeyOnlyCacheType

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::KeyOnlyCacheType = hardened_partitioned_hash_map<key_type, KeyOnlyEntry, Hash, KeyEqual>
private

Definition at line 331 of file TaggedCache.h.

◆ KeyValueCacheType

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::KeyValueCacheType = hardened_partitioned_hash_map<key_type, ValueEntry, Hash, KeyEqual>
private

Definition at line 333 of file TaggedCache.h.

◆ cache_type

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
using xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::cache_type = hardened_partitioned_hash_map<key_type, Entry, Hash, KeyEqual>
private

Definition at line 335 of file TaggedCache.h.

Constructor & Destructor Documentation

◆ TaggedCache()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::TaggedCache ( std::string const & name,
int size,
clock_type::duration expiration,
clock_type & clock,
beast::Journal journal,
beast::insight::Collector::ptr const & collector = beast::insight::NullCollector::make() )

Member Function Documentation

◆ clock()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
clock_type & xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clock ( )

Return the clock associated with the cache.

◆ size()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::size_t xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::size ( ) const

Returns the number of items in the container.

◆ getCacheSize()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
int xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getCacheSize ( ) const

◆ getTrackSize()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
int xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getTrackSize ( ) const

◆ getHitRate()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
float xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getHitRate ( )

◆ clear()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
void xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clear ( )

◆ reset()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
void xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::reset ( )

◆ touchIfExists()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<class KeyComparable>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::touchIfExists ( KeyComparable const & key)

Refresh the last access time on a key if present.

Returns
true If the key was found.

◆ sweep()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
void xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::sweep ( )

◆ del()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::del ( key_type const & key,
bool valid )

◆ canonicalizeImpl()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<class Policy, class Callback = std::nullptr_t>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalizeImpl ( key_type const & key,
CanonicalizeClientPointerType< Policy > data,
Policy policy,
Callback && replaceCallback = nullptr )
private

Shared implementation of the canonicalize family.

policy selects how a collision is resolved when key already exists: detail::ReplaceCached, detail::ReplaceClient or detail::ReplaceDynamically. For ReplaceDynamically replaceCallback is invoked with the existing strong pointer and returns whether to replace the cached value with data; for the tag policies it is unused.

◆ canonicalize()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<class Callback>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalize ( key_type const & key,
SharedPointerType & data,
Callback && replaceCallback )

Replace aliased objects with originals.

Due to concurrency it is possible for two separate objects with the same content and referring to the same unique "thing" to exist. This routine eliminates the duplicate and performs a replacement on the callers shared pointer if needed.

replaceCallback is a callable taking the existing strong pointer and returning whether to replace the cached value with data (true) or to keep the cached value and write it back into data (false). Because the write-back case mutates data, data must be writable.

Parameters
keyThe key corresponding to the object
dataA shared pointer to the data corresponding to the object.
replaceCallbackA callable (existing strong pointer -> bool).
Returns
true if an existing live entry was found and used; false if a new entry was inserted or an expired tracked entry was re-cached.

◆ canonicalizeReplaceCache()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalizeReplaceCache ( key_type const & key,
SharedPointerType const & data )

Insert/update the canonical entry for key, always replacing the cached value with data.

If an entry already exists for key, the cached value is unconditionally replaced with data; otherwise data is inserted. data is never written back, so it may be const.

Parameters
keyThe key corresponding to the object.
dataA shared pointer to the data corresponding to the object.
Returns
true if an existing live entry was found and used; false if a new entry was inserted or an expired tracked entry was re-cached.

◆ canonicalizeReplaceClient()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalizeReplaceClient ( key_type const & key,
SharedPointerType & data )

Insert the canonical entry for key, keeping any existing cached value.

If an entry already exists for key, the cached value is kept and written back into data so the caller ends up with the canonical object; otherwise data is inserted. Because data may be overwritten it must be writable.

Parameters
keyThe key corresponding to the object.
dataA shared pointer to the data corresponding to the object; updated to the canonical value when one already exists.
Returns
true if an existing live entry was found and used; false if a new entry was inserted or an expired tracked entry was re-cached.

◆ fetch() [1/2]

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
SharedPointerType xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::fetch ( key_type const & key)

◆ insert() [1/2]

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<class ReturnType = bool>
auto xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::insert ( key_type const & key,
T const & value ) -> std::enable_if_t<!IsKeyCache, ReturnType >

Insert the element into the container.

If the key already exists, nothing happens.

Returns
true If the element was inserted

◆ insert() [2/2]

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<class ReturnType = bool>
auto xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::insert ( key_type const & key) -> std::enable_if_t< IsKeyCache, ReturnType >

◆ retrieve()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
bool xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::retrieve ( key_type const & key,
T & data )

◆ peekMutex()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
mutex_type & xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::peekMutex ( )

◆ getKeys()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::vector< key_type > xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getKeys ( ) const

◆ rate()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
double xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::rate ( ) const

Returns the fraction of cache hits.

◆ fetch() [2/2]

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
template<class Handler>
SharedPointerType xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::fetch ( key_type const & digest,
Handler const & h )

Fetch an item from the cache.

If the digest was not found, Handler will be called with this signature: SLE::const_pointer(void)

◆ initialFetch()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
SharedPointerType xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::initialFetch ( key_type const & key,
std::scoped_lock< mutex_type > const & l )
private

◆ collectMetrics()

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
void xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::collectMetrics ( )
private

◆ sweepHelper() [1/2]

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::thread xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::sweepHelper ( clock_type::time_point const & whenExpire,
clock_type::time_point const & now,
KeyValueCacheType::map_type & partition,
SweptPointersVector & stuffToSweep,
std::atomic< int > & allRemovals,
std::scoped_lock< std::recursive_mutex > const &  )
nodiscardprivate

◆ sweepHelper() [2/2]

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::thread xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::sweepHelper ( clock_type::time_point const & whenExpire,
clock_type::time_point const & now,
KeyOnlyCacheType::map_type & partition,
SweptPointersVector & ,
std::atomic< int > & allRemovals,
std::scoped_lock< std::recursive_mutex > const &  )
nodiscardprivate

Member Data Documentation

◆ journal_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
beast::Journal xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::journal_
private

Definition at line 355 of file TaggedCache.h.

◆ clock_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
clock_type& xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clock_
private

Definition at line 356 of file TaggedCache.h.

◆ stats_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
Stats xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::stats_
private

Definition at line 357 of file TaggedCache.h.

◆ mutex_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
mutex_type xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::mutex_
mutableprivate

Definition at line 359 of file TaggedCache.h.

◆ name_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::string xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::name_
private

Definition at line 362 of file TaggedCache.h.

◆ targetSize_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
int const xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::targetSize_
private

Definition at line 365 of file TaggedCache.h.

◆ targetAge_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
clock_type::duration const xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::targetAge_
private

Definition at line 368 of file TaggedCache.h.

◆ cacheCount_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
int xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::cacheCount_ {0}
private

Definition at line 371 of file TaggedCache.h.

◆ cache_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
cache_type xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::cache_
private

Definition at line 372 of file TaggedCache.h.

◆ hits_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::uint64_t xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::hits_ {0}
private

Definition at line 373 of file TaggedCache.h.

◆ misses_

template<class Key, class T, bool IsKeyCache = false, class SharedWeakUnionPointerType = SharedWeakCachePointer<T>, class SharedPointerType = std::shared_ptr<T>, class Hash = HardenedHash<>, class KeyEqual = std::equal_to<Key>, class Mutex = std::recursive_mutex>
std::uint64_t xrpl::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::misses_ {0}
private

Definition at line 374 of file TaggedCache.h.