3#include <xrpl/basics/SharedWeakCachePointer.h>
4#include <xrpl/basics/SharedWeakCachePointer.ipp>
5#include <xrpl/basics/UnorderedContainers.h>
6#include <xrpl/basics/hardened_hash.h>
7#include <xrpl/beast/clock/abstract_clock.h>
8#include <xrpl/beast/insight/Collector.h>
9#include <xrpl/beast/insight/Gauge.h>
10#include <xrpl/beast/insight/Hook.h>
11#include <xrpl/beast/insight/NullCollector.h>
12#include <xrpl/beast/utility/Journal.h>
40struct ReplaceDynamically;
60 bool IsKeyCache =
false,
62 class SharedPointerType = std::shared_ptr<T>,
65 class Mutex = std::recursive_mutex>
117 template <
class KeyComparable>
133 template <
typename Policy>
136 SharedPointerType
const&,
148 template <
class Policy,
class Callback = std::
nullptr_t>
154 Callback&& replaceCallback =
nullptr);
177 template <
class Callback>
224 template <
class ReturnType =
bool>
227 requires(!IsKeyCache);
229 template <
class ReturnType =
bool>
261 template <
class Handler>
276 template <
class Handler>
279 Handler
const& handler,
281 :
hook(collector->makeHook(handler))
282 ,
size(collector->makeGauge(prefix,
"size"))
283 ,
hitRate(collector->makeGauge(prefix,
"hit_rate"))
333 return ptr &&
ptr.isStrong();
338 return ptr.expired();
Abstract interface to a clock.
std::chrono::steady_clock::duration duration
std::chrono::steady_clock::time_point time_point
A generic endpoint for log messages.
std::shared_ptr< Collector > ptr
A metric for measuring an integral value.
A reference to a handler for performing polled collection.
static std::shared_ptr< Collector > make()
Seed functor once per construction.
std::unordered_map< key_type, mapped_type, hasher, key_equal, allocator_type > map_type
A combination of a std::shared_ptr and a std::weak_pointer.
void touch(clock_type::time_point const &now)
clock_type::time_point lastAccess
KeyOnlyEntry(clock_type::time_point const &lastAccess)
clock_type::time_point lastAccess
void touch(clock_type::time_point const &now)
shared_weak_combo_pointer_type ptr
ValueEntry(clock_type::time_point const &lastAccess, shared_pointer_type const &ptr)
std::shared_ptr< int > shared_pointer_type
std::vector< key_type > getKeys() const
hardened_partitioned_hash_map< key_type, ValueEntry, HardenedHash<>, std::equal_to< uint256 > > KeyValueCacheType
bool del(key_type const &key, bool valid)
bool retrieve(key_type const &key, T &data)
bool canonicalizeReplaceClient(key_type const &key, SharedPointerType &data)
Insert the canonical entry for key, keeping any existing cached value.
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 &)
bool touchIfExists(KeyComparable const &key)
Refresh the last access time on a key if present.
SharedWeakCachePointer< int > shared_weak_combo_pointer_type
std::recursive_mutex mutex_type
beast::AbstractClock< std::chrono::steady_clock > clock_type
SharedPointerType fetch(key_type const &digest, Handler const &h)
Fetch an item from the cache.
hardened_partitioned_hash_map< key_type, KeyOnlyEntry, HardenedHash<>, std::equal_to< uint256 > > KeyOnlyCacheType
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 &)
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())
std::conditional_t< std::is_same_v< detail::ReplaceCached, Policy >, std::shared_ptr< int > const &, std::shared_ptr< int > & > CanonicalizeClientPointerType
hardened_partitioned_hash_map< key_type, Entry, HardenedHash<>, std::equal_to< uint256 > > cache_type
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)
bool canonicalize(key_type const &key, SharedPointerType &data, Callback &&replaceCallback)
Replace aliased objects with originals.
std::vector< SharedWeakCachePointer< int > > SweptPointersVector
bool canonicalizeReplaceCache(key_type const &key, SharedPointerType const &data)
Insert/update the canonical entry for key, always replacing the cached value with data.
clock_type::duration const targetAge_
SharedPointerType fetch(key_type const &key)
double rate() const
Returns the fraction of cache hits.
std::conditional_t< IsKeyCache, KeyOnlyEntry, ValueEntry > Entry
auto insert(key_type const &key, T const &value) -> ReturnType requires(!IsKeyCache)
Insert the element into the container.
auto insert(key_type const &key) -> ReturnType
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
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
PartitionedUnorderedMap< Key, Value, Hash, Pred, Allocator > hardened_partitioned_hash_map
Stats(std::string const &prefix, Handler const &handler, beast::insight::Collector::ptr const &collector)
beast::insight::Gauge size
beast::insight::Hook hook
beast::insight::Gauge hitRate