|
rippled
|
Map/cache combination. More...
#include <TaggedCache.h>

Classes | |
| class | KeyOnlyEntry |
| struct | Stats |
| class | ValueEntry |
Public Types | |
| using | mutex_type = Mutex |
| using | key_type = Key |
| using | mapped_type = T |
| using | clock_type = beast::abstract_clock< 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::New()) | |
| 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 | touch_if_exists (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 R > | |
| bool | canonicalize (key_type const &key, SharedPointerType &data, R &&replaceCallback) |
| Replace aliased objects with originals. | |
| bool | canonicalize_replace_cache (key_type const &key, SharedPointerType const &data) |
| bool | canonicalize_replace_client (key_type const &key, SharedPointerType &data) |
| 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. | |
Private Types | |
| typedef std::conditional< IsKeyCache, KeyOnlyEntry, ValueEntry >::type | Entry |
| 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 | |
| SharedPointerType | initialFetch (key_type const &key, std::lock_guard< mutex_type > const &l) |
| void | collect_metrics () |
| std::thread | sweepHelper (clock_type::time_point const &when_expire, clock_type::time_point const &now, typename KeyValueCacheType::map_type &partition, SweptPointersVector &stuffToSweep, std::atomic< int > &allRemovals, std::lock_guard< std::recursive_mutex > const &) |
| std::thread | sweepHelper (clock_type::time_point const &when_expire, clock_type::time_point const &now, typename KeyOnlyCacheType::map_type &partition, SweptPointersVector &, std::atomic< int > &allRemovals, std::lock_guard< std::recursive_mutex > const &) |
Private Attributes | |
| beast::Journal | m_journal |
| clock_type & | m_clock |
| Stats | m_stats |
| mutex_type | m_mutex |
| std::string | m_name |
| int const | m_target_size |
| clock_type::duration const | m_target_age |
| int | m_cache_count |
| cache_type | m_cache |
| std::uint64_t | m_hits |
| std::uint64_t | m_misses |
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.
Definition at line 42 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::mutex_type = Mutex |
Definition at line 45 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::key_type = Key |
Definition at line 46 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::mapped_type = T |
Definition at line 47 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clock_type = beast::abstract_clock<std::chrono::steady_clock> |
Definition at line 48 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::shared_weak_combo_pointer_type = SharedWeakUnionPointerType |
Definition at line 49 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::shared_pointer_type = SharedPointerType |
Definition at line 50 of file TaggedCache.h.
| using ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::SweptPointersVector = std::vector<SharedWeakUnionPointerType> |
Definition at line 93 of file TaggedCache.h.
|
private |
Definition at line 267 of file TaggedCache.h.
|
private |
Definition at line 269 of file TaggedCache.h.
|
private |
Definition at line 272 of file TaggedCache.h.
|
private |
Definition at line 275 of file TaggedCache.h.
| ripple::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::New() |
||
| ) |
| clock_type & ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clock | ( | ) |
Return the clock associated with the cache.
| std::size_t ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::size | ( | ) | const |
Returns the number of items in the container.
| int ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getCacheSize | ( | ) | const |
| int ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getTrackSize | ( | ) | const |
| float ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getHitRate | ( | ) |
| void ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::clear | ( | ) |
| void ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::reset | ( | ) |
| bool ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::touch_if_exists | ( | KeyComparable const & | key | ) |
Refresh the last access time on a key if present.
true If the key was found. | void ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::sweep | ( | ) |
| bool ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::del | ( | key_type const & | key, |
| bool | valid | ||
| ) |
| bool ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalize | ( | key_type const & | key, |
| SharedPointerType & | data, | ||
| R && | 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.
| key | The key corresponding to the object |
| data | A shared pointer to the data corresponding to the object. |
| replace | Function that decides if cache should be replaced |
true If the key already existed. | bool ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalize_replace_cache | ( | key_type const & | key, |
| SharedPointerType const & | data | ||
| ) |
| bool ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::canonicalize_replace_client | ( | key_type const & | key, |
| SharedPointerType & | data | ||
| ) |
| SharedPointerType ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::fetch | ( | key_type const & | key | ) |
| auto ripple::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.
true If the element was inserted | auto ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::insert | ( | key_type const & | key | ) | -> std::enable_if_t< IsKeyCache, ReturnType > |
| bool ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::retrieve | ( | key_type const & | key, |
| T & | data | ||
| ) |
| mutex_type & ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::peekMutex | ( | ) |
| std::vector< key_type > ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::getKeys | ( | ) | const |
| double ripple::TaggedCache< Key, T, IsKeyCache, SharedWeakUnionPointerType, SharedPointerType, Hash, KeyEqual, Mutex >::rate | ( | ) | const |
Returns the fraction of cache hits.
| SharedPointerType ripple::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: std::shared_ptr<SLE const>(void)
|
private |
|
private |
|
private |
|
private |
|
private |
Definition at line 296 of file TaggedCache.h.
|
private |
Definition at line 297 of file TaggedCache.h.
|
private |
Definition at line 298 of file TaggedCache.h.
|
mutableprivate |
Definition at line 300 of file TaggedCache.h.
|
private |
Definition at line 303 of file TaggedCache.h.
|
private |
Definition at line 306 of file TaggedCache.h.
|
private |
Definition at line 309 of file TaggedCache.h.
|
private |
Definition at line 312 of file TaggedCache.h.
|
private |
Definition at line 313 of file TaggedCache.h.
|
private |
Definition at line 314 of file TaggedCache.h.
|
private |
Definition at line 315 of file TaggedCache.h.