xrpld
Loading...
Searching...
No Matches
FullBelowCache.h
1#pragma once
2
3#include <xrpl/basics/KeyCache.h>
4#include <xrpl/basics/TaggedCache.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/insight/Collector.h>
7#include <xrpl/beast/insight/NullCollector.h>
8#include <xrpl/beast/utility/Journal.h>
9
10#include <atomic>
11#include <chrono>
12#include <cstddef>
13#include <cstdint>
14#include <string>
15
16namespace xrpl {
17
18namespace detail {
19
25{
26private:
28
29public:
30 static constexpr auto kDefaultCacheTargetSize = 0;
31
34
44 std::string const& name,
50 : cache_(name, targetSize, expiration, clock, j, collector), gen_(1)
51 {
52 }
53
59 {
60 return cache_.clock();
61 }
62
69 size() const
70 {
71 return cache_.size();
72 }
73
79 void
81 {
82 cache_.sweep();
83 }
84
92 bool
94 {
95 return cache_.touchIfExists(key);
96 }
97
106 void
107 insert(key_type const& key)
108 {
109 cache_.insert(key);
110 }
111
117 {
118 return gen_;
119 }
120
121 void
123 {
124 cache_.clear();
125 ++gen_;
126 }
127
128 void
130 {
131 cache_.clear();
132 gen_ = 1;
133 }
134
135private:
138};
139
140} // namespace detail
141
143
144} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
std::shared_ptr< Collector > ptr
Definition Collector.h:29
static std::shared_ptr< Collector > make()
beast::AbstractClock< std::chrono::steady_clock > clock_type
Definition TaggedCache.h:72
Remembers which tree keys have all descendants resident.
void sweep()
Remove expired cache items.
static constexpr auto kDefaultCacheTargetSize
bool touchIfExists(key_type const &key)
Refresh the last access time of an item, if it exists.
std::atomic< std::uint32_t > gen_
BasicFullBelowCache(std::string const &name, clock_type &clock, beast::Journal j, beast::insight::Collector::ptr const &collector=beast::insight::NullCollector::make(), std::size_t targetSize=kDefaultCacheTargetSize, std::chrono::seconds expiration=std::chrono::minutes{2})
Construct the cache.
std::size_t size() const
Return the number of elements in the cache.
CacheType::clock_type clock_type
std::uint32_t getGeneration() const
generation determines whether cached entry is valid
void insert(key_type const &key)
Insert a key into the cache.
clock_type & clock()
Return the clock associated with the cache.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
detail::BasicFullBelowCache FullBelowCache
TaggedCache< uint256, int, true > KeyCache
Definition KeyCache.h:8
BaseUInt< 256 > uint256
Definition base_uint.h:580