rippled
Loading...
Searching...
No Matches
FullBelowCache.h
1#ifndef XRPL_SHAMAP_FULLBELOWCACHE_H_INCLUDED
2#define XRPL_SHAMAP_FULLBELOWCACHE_H_INCLUDED
3
4#include <xrpl/basics/KeyCache.h>
5#include <xrpl/basics/TaggedCache.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/beast/insight/Collector.h>
8#include <xrpl/beast/utility/Journal.h>
9
10#include <atomic>
11#include <string>
12
13namespace ripple {
14
15namespace detail {
16
21{
22private:
24
25public:
27
30
39 std::string const& name,
42 beast::insight::Collector::ptr const& collector =
46 : m_cache(name, target_size, expiration, clock, j, collector), m_gen(1)
47 {
48 }
49
53 {
54 return m_cache.clock();
55 }
56
62 size() const
63 {
64 return m_cache.size();
65 }
66
71 void
73 {
74 m_cache.sweep();
75 }
76
83 bool
85 {
86 return m_cache.touch_if_exists(key);
87 }
88
96 void
97 insert(key_type const& key)
98 {
99 m_cache.insert(key);
100 }
101
104 getGeneration(void) const
105 {
106 return m_gen;
107 }
108
109 void
111 {
112 m_cache.clear();
113 ++m_gen;
114 }
115
116 void
118 {
119 m_cache.clear();
120 m_gen = 1;
121 }
122
123private:
126};
127
128} // namespace detail
129
131
132} // namespace ripple
133
134#endif
A generic endpoint for log messages.
Definition Journal.h:41
static std::shared_ptr< Collector > New()
Map/cache combination.
Definition TaggedCache.h:43
bool touch_if_exists(KeyComparable const &key)
Refresh the last access time on a key if present.
beast::abstract_clock< std::chrono::steady_clock > clock_type
Definition TaggedCache.h:48
clock_type & clock()
Return the clock associated with the cache.
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.
Remembers which tree keys have all descendants resident.
std::atomic< std::uint32_t > m_gen
void insert(key_type const &key)
Insert a key into the cache.
void sweep()
Remove expired cache items.
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.
typename CacheType::clock_type clock_type
clock_type & clock()
Return the clock associated with the cache.
std::uint32_t getGeneration(void) const
generation determines whether cached entry is valid
bool touch_if_exists(key_type const &key)
Refresh the last access time of an item, if it exists.
std::size_t size() const
Return the number of elements in the cache.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 256 > uint256
Definition base_uint.h:539
TaggedCache< uint256, int, true > KeyCache
Definition KeyCache.h:9