20#ifndef RIPPLE_BASICS_TAGGEDCACHE_H_INCLUDED
21#define RIPPLE_BASICS_TAGGEDCACHE_H_INCLUDED
23#include <xrpl/basics/IntrusivePointer.h>
24#include <xrpl/basics/Log.h>
25#include <xrpl/basics/SharedWeakCachePointer.ipp>
26#include <xrpl/basics/UnorderedContainers.h>
27#include <xrpl/basics/hardened_hash.h>
28#include <xrpl/beast/clock/abstract_clock.h>
29#include <xrpl/beast/insight/Insight.h>
55 bool IsKeyCache =
false,
56 class SharedWeakUnionPointerType = SharedWeakCachePointer<T>,
58 class Hash = hardened_hash<>,
108 template <
class KeyComparable>
138 SharedPointerType& data,
139 R&& replaceCallback);
144 SharedPointerType
const& data);
156 template <
class ReturnType =
bool>
161 template <
class ReturnType =
bool>
189 template <
class Handler>
204 template <
class Handler>
207 Handler
const& handler,
209 :
hook(collector->make_hook(handler))
210 ,
size(collector->make_gauge(prefix,
"size"))
211 ,
hit_rate(collector->make_gauge(prefix,
"hit_rate"))
265 return ptr &&
ptr.isStrong();
270 return ptr.expired();
A generic endpoint for log messages.
typename Clock::time_point time_point
typename Clock::duration duration
A metric for measuring an integral value.
A reference to a handler for performing polled collection.
static std::shared_ptr< Collector > New()
void touch(clock_type::time_point const &now)
KeyOnlyEntry(clock_type::time_point const &last_access_)
clock_type::time_point last_access
ValueEntry(clock_type::time_point const &last_access_, shared_pointer_type const &ptr_)
shared_weak_combo_pointer_type ptr
clock_type::time_point last_access
void touch(clock_type::time_point const &now)
bool touch_if_exists(KeyComparable const &key)
Refresh the last access time on a key if present.
bool retrieve(const key_type &key, T &data)
bool canonicalize(const key_type &key, SharedPointerType &data, R &&replaceCallback)
Replace aliased objects with originals.
bool del(const key_type &key, bool valid)
bool canonicalize_replace_cache(const key_type &key, SharedPointerType const &data)
clock_type & clock()
Return the clock associated with the cache.
SharedWeakUnionPointerType shared_weak_combo_pointer_type
SharedPointerType fetch(key_type const &digest, Handler const &h)
Fetch an item from the cache.
auto insert(key_type const &key, T const &value) -> std::enable_if_t<!IsKeyCache, ReturnType >
Insert the element into the container.
std::vector< key_type > getKeys() const
SharedPointerType fetch(const key_type &key)
std::size_t size() const
Returns the number of items in the container.
SharedPointerType shared_pointer_type
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 &)
SharedPointerType initialFetch(key_type const &key, std::lock_guard< mutex_type > const &l)
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::conditional< IsKeyCache, KeyOnlyEntry, ValueEntry >::type Entry
double rate() const
Returns the fraction of cache hits.
const clock_type::duration m_target_age
auto insert(key_type const &key) -> std::enable_if_t< IsKeyCache, ReturnType >
bool canonicalize_replace_client(const key_type &key, SharedPointerType &data)
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())
TER valid(PreclaimContext const &ctx, AccountID const &src)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static Hasher::result_type digest(void const *data, std::size_t size) noexcept
beast::insight::Gauge size
beast::insight::Hook hook
beast::insight::Gauge hit_rate
Stats(std::string const &prefix, Handler const &handler, beast::insight::Collector::ptr const &collector)