rippled
|
Map/cache combination. More...
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 | SweptPointersVector = std::pair< std::vector< std::shared_ptr< mapped_type > >, std::vector< std::weak_ptr< mapped_type > >> |
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. More... | |
std::size_t | size () const |
Returns the number of items in the container. More... | |
void | setTargetSize (int s) |
clock_type::duration | getTargetAge () const |
void | setTargetAge (clock_type::duration s) |
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. More... | |
void | sweep () |
bool | del (const key_type &key, bool valid) |
bool | canonicalize (const key_type &key, std::shared_ptr< T > &data, std::function< bool(std::shared_ptr< T > const &)> &&replace) |
Replace aliased objects with originals. More... | |
bool | canonicalize_replace_cache (const key_type &key, std::shared_ptr< T > const &data) |
bool | canonicalize_replace_client (const key_type &key, std::shared_ptr< T > &data) |
std::shared_ptr< T > | fetch (const key_type &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. More... | |
template<class ReturnType = bool> | |
auto | insert (key_type const &key) -> std::enable_if_t< IsKeyCache, ReturnType > |
bool | retrieve (const key_type &key, T &data) |
mutex_type & | peekMutex () |
std::vector< key_type > | getKeys () const |
double | rate () const |
Returns the fraction of cache hits. More... | |
template<class Handler > | |
std::shared_ptr< T > | fetch (key_type const &digest, Handler const &h) |
Fetch an item from the cache. More... | |
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 | |
std::shared_ptr< T > | 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, [[maybe_unused]] 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 &) |
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 64 of file Application.h.
using ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::mutex_type = Mutex |
Definition at line 59 of file TaggedCache.h.
using ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::key_type = Key |
Definition at line 60 of file TaggedCache.h.
using ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::mapped_type = T |
Definition at line 61 of file TaggedCache.h.
using ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::clock_type = beast::abstract_clock<std::chrono::steady_clock> |
Definition at line 62 of file TaggedCache.h.
using ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::SweptPointersVector = std::pair< std::vector<std::shared_ptr<mapped_type> >, std::vector<std::weak_ptr<mapped_type> >> |
Definition at line 201 of file TaggedCache.h.
|
private |
Definition at line 642 of file TaggedCache.h.
|
private |
Definition at line 645 of file TaggedCache.h.
|
private |
Definition at line 648 of file TaggedCache.h.
|
private |
Definition at line 651 of file TaggedCache.h.
ripple::TaggedCache< Key, T, IsKeyCache, 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() |
||
) |
Definition at line 65 of file TaggedCache.h.
clock_type& ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::clock | ( | ) |
Return the clock associated with the cache.
Definition at line 91 of file TaggedCache.h.
std::size_t ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::size | ( | ) | const |
Returns the number of items in the container.
Definition at line 98 of file TaggedCache.h.
void ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::setTargetSize | ( | int | s | ) |
Definition at line 105 of file TaggedCache.h.
clock_type::duration ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::getTargetAge | ( | ) | const |
Definition at line 125 of file TaggedCache.h.
void ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::setTargetAge | ( | clock_type::duration | s | ) |
Definition at line 132 of file TaggedCache.h.
int ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::getCacheSize | ( | ) | const |
Definition at line 141 of file TaggedCache.h.
int ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::getTrackSize | ( | ) | const |
Definition at line 148 of file TaggedCache.h.
float ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::getHitRate | ( | ) |
Definition at line 155 of file TaggedCache.h.
void ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::clear | ( | ) |
Definition at line 163 of file TaggedCache.h.
void ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::reset | ( | ) |
Definition at line 171 of file TaggedCache.h.
bool ripple::TaggedCache< Key, T, IsKeyCache, 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. Definition at line 185 of file TaggedCache.h.
void ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::sweep | ( | ) |
Definition at line 204 of file TaggedCache.h.
bool ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::del | ( | const key_type & | key, |
bool | valid | ||
) |
Definition at line 269 of file TaggedCache.h.
bool ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::canonicalize | ( | const key_type & | key, |
std::shared_ptr< T > & | data, | ||
std::function< bool(std::shared_ptr< T > const &)> && | replace | ||
) |
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. Definition at line 312 of file TaggedCache.h.
bool ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::canonicalize_replace_cache | ( | const key_type & | key, |
std::shared_ptr< T > const & | data | ||
) |
Definition at line 378 of file TaggedCache.h.
bool ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::canonicalize_replace_client | ( | const key_type & | key, |
std::shared_ptr< T > & | data | ||
) |
Definition at line 389 of file TaggedCache.h.
std::shared_ptr<T> ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::fetch | ( | const key_type & | key | ) |
Definition at line 396 of file TaggedCache.h.
auto ripple::TaggedCache< Key, T, IsKeyCache, 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 Definition at line 411 of file TaggedCache.h.
auto ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::insert | ( | key_type const & | key | ) | -> std::enable_if_t<IsKeyCache, ReturnType> |
Definition at line 420 of file TaggedCache.h.
bool ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::retrieve | ( | const key_type & | key, |
T & | data | ||
) |
Definition at line 439 of file TaggedCache.h.
mutex_type& ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::peekMutex | ( | ) |
Definition at line 452 of file TaggedCache.h.
std::vector<key_type> ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::getKeys | ( | ) | const |
Definition at line 458 of file TaggedCache.h.
double ripple::TaggedCache< Key, T, IsKeyCache, Hash, KeyEqual, Mutex >::rate | ( | ) | const |
Returns the fraction of cache hits.
Definition at line 475 of file TaggedCache.h.
std::shared_ptr<T> ripple::TaggedCache< Key, T, IsKeyCache, 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)
Definition at line 491 of file TaggedCache.h.
|
private |
Definition at line 515 of file TaggedCache.h.
|
private |
Definition at line 542 of file TaggedCache.h.
|
private |
Definition at line 654 of file TaggedCache.h.
|
private |
Definition at line 728 of file TaggedCache.h.
|
private |
Definition at line 772 of file TaggedCache.h.
|
private |
Definition at line 775 of file TaggedCache.h.
|
private |
Definition at line 776 of file TaggedCache.h.
|
mutableprivate |
Definition at line 778 of file TaggedCache.h.
|
private |
Definition at line 781 of file TaggedCache.h.
|
private |
Definition at line 784 of file TaggedCache.h.
|
private |
Definition at line 787 of file TaggedCache.h.
|
private |
Definition at line 790 of file TaggedCache.h.
|
private |
Definition at line 791 of file TaggedCache.h.
|
private |
Definition at line 792 of file TaggedCache.h.
|
private |
Definition at line 793 of file TaggedCache.h.