|
| | 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_type & | clock () |
| | 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_type & | peekMutex () |
| std::vector< key_type > | getKeys () 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.
|
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.
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.
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.
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
-
| key | The key corresponding to the object |
| data | A shared pointer to the data corresponding to the object. |
| replaceCallback | A 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.
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
-
| key | The key corresponding to the object. |
| data | A 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.
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
-
| key | The key corresponding to the object. |
| data | A 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.
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
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)