3#include <xrpl/basics/IntrusivePointer.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/basics/SharedWeakCachePointer.ipp>
6#include <xrpl/basics/UnorderedContainers.h>
7#include <xrpl/basics/hardened_hash.h>
8#include <xrpl/beast/clock/abstract_clock.h>
9#include <xrpl/beast/insight/Insight.h>
33struct ReplaceDynamically;
52 bool IsKeyCache =
false,
54 class SharedPointerType = std::shared_ptr<T>,
57 class Mutex = std::recursive_mutex>
104 template <
class KeyComparable>
120 template <
typename Policy>
123 SharedPointerType
const&,
134 template <
class Policy,
class Callback = std::
nullptr_t>
140 Callback&& replaceCallback =
nullptr);
162 template <
class Callback>
206 template <
class ReturnType =
bool>
210 template <
class ReturnType =
bool>
238 template <
class Handler>
253 template <
class Handler>
256 Handler
const& handler,
258 :
hook(collector->makeHook(handler))
259 ,
size(collector->makeGauge(prefix,
"size"))
260 ,
hitRate(collector->makeGauge(prefix,
"hit_rate"))
310 return ptr &&
ptr.isStrong();
315 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.
auto insert(key_type const &key, T const &value) -> std::enable_if_t<!IsKeyCache, ReturnType >
Insert the element into the container.
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 &)
auto insert(key_type const &key) -> std::enable_if_t< IsKeyCache, ReturnType >
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
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