rippled
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/utility/Journal.h>
8
9#include <atomic>
10#include <string>
11
12namespace xrpl {
13
14namespace detail {
15
20{
21private:
23
24public:
26
29
38 std::string const& name,
44 : m_cache(name, target_size, expiration, clock, j, collector), m_gen(1)
45 {
46 }
47
51 {
52 return m_cache.clock();
53 }
54
60 size() const
61 {
62 return m_cache.size();
63 }
64
69 void
71 {
72 m_cache.sweep();
73 }
74
81 bool
83 {
84 return m_cache.touch_if_exists(key);
85 }
86
94 void
95 insert(key_type const& key)
96 {
97 m_cache.insert(key);
98 }
99
102 getGeneration(void) const
103 {
104 return m_gen;
105 }
106
107 void
109 {
110 m_cache.clear();
111 ++m_gen;
112 }
113
114 void
116 {
117 m_cache.clear();
118 m_gen = 1;
119 }
120
121private:
124};
125
126} // namespace detail
127
129
130} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
static std::shared_ptr< Collector > New()
Map/cache combination.
Definition TaggedCache.h:42
beast::abstract_clock< std::chrono::steady_clock > clock_type
Definition TaggedCache.h:47
auto insert(key_type const &key, T const &value) -> std::enable_if_t<!IsKeyCache, ReturnType >
Insert the element into the container.
std::size_t size() const
Returns the number of items in the container.
bool touch_if_exists(KeyComparable const &key)
Refresh the last access time on a key if present.
clock_type & clock()
Return the clock associated with the cache.
Remembers which tree keys have all descendants resident.
void sweep()
Remove expired cache items.
std::atomic< std::uint32_t > m_gen
typename CacheType::clock_type clock_type
std::size_t size() const
Return the number of elements in the cache.
BasicFullBelowCache(std::string const &name, clock_type &clock, beast::Journal j, beast::insight::Collector::ptr const &collector=beast::insight::NullCollector::New(), std::size_t target_size=defaultCacheTargetSize, std::chrono::seconds expiration=std::chrono::minutes{2})
Construct the cache.
bool touch_if_exists(key_type const &key)
Refresh the last access time of an item, if it exists.
void insert(key_type const &key)
Insert a key into the cache.
clock_type & clock()
Return the clock associated with the cache.
std::uint32_t getGeneration(void) const
generation determines whether cached entry is valid
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TaggedCache< uint256, int, true > KeyCache
Definition KeyCache.h:8
base_uint< 256 > uint256
Definition base_uint.h:526