xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
shamap
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
16
namespace
xrpl
{
17
18
namespace
detail
{
19
24
class
BasicFullBelowCache
25
{
26
private
:
27
using
CacheType
=
KeyCache
;
28
29
public
:
30
static
constexpr
auto
kDefaultCacheTargetSize
= 0;
31
32
using
key_type
=
UInt256
;
33
using
ClockType
=
CacheType::ClockType
;
34
43
BasicFullBelowCache
(
44
std::string
const
& name,
45
ClockType
&
clock
,
46
beast::Journal
j,
47
beast::insight::Collector::Ptr
const
& collector =
beast::insight::NullCollector::make
(),
48
std::size_t
targetSize =
kDefaultCacheTargetSize
,
49
std::chrono::seconds
expiration =
std::chrono::minutes
{2})
50
:
cache_
(name, targetSize, expiration,
clock
, j, collector),
gen_
(1)
51
{
52
}
53
57
ClockType
&
58
clock
()
59
{
60
return
cache_
.clock();
61
}
62
68
std::size_t
69
size
()
const
70
{
71
return
cache_
.size();
72
}
73
79
void
80
sweep
()
81
{
82
cache_
.sweep();
83
}
84
92
bool
93
touchIfExists
(
key_type
const
& key)
94
{
95
return
cache_
.touchIfExists(key);
96
}
97
106
void
107
insert
(
key_type
const
& key)
108
{
109
cache_
.insert(key);
110
}
111
115
std::uint32_t
116
getGeneration
()
const
117
{
118
return
gen_
;
119
}
120
121
void
122
clear
()
123
{
124
cache_
.clear();
125
++
gen_
;
126
}
127
128
void
129
reset
()
130
{
131
cache_
.clear();
132
gen_
= 1;
133
}
134
135
private
:
136
CacheType
cache_
;
137
std::atomic<std::uint32_t>
gen_
;
138
};
139
140
}
// namespace detail
141
142
using
FullBelowCache
=
detail::BasicFullBelowCache
;
143
144
}
// namespace xrpl
atomic
std::string
chrono
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::insight::Collector::Ptr
std::shared_ptr< Collector > Ptr
Definition
Collector.h:29
beast::insight::NullCollector::make
static std::shared_ptr< Collector > make()
Definition
NullCollector.cpp:146
xrpl::TaggedCache< UInt256, int, true >::ClockType
beast::AbstractClock< std::chrono::steady_clock > ClockType
Definition
TaggedCache.h:72
xrpl::detail::BasicFullBelowCache
Remembers which tree keys have all descendants resident.
Definition
FullBelowCache.h:25
xrpl::detail::BasicFullBelowCache::sweep
void sweep()
Remove expired cache items.
Definition
FullBelowCache.h:80
xrpl::detail::BasicFullBelowCache::kDefaultCacheTargetSize
static constexpr auto kDefaultCacheTargetSize
Definition
FullBelowCache.h:30
xrpl::detail::BasicFullBelowCache::touchIfExists
bool touchIfExists(key_type const &key)
Refresh the last access time of an item, if it exists.
Definition
FullBelowCache.h:93
xrpl::detail::BasicFullBelowCache::gen_
std::atomic< std::uint32_t > gen_
Definition
FullBelowCache.h:137
xrpl::detail::BasicFullBelowCache::reset
void reset()
Definition
FullBelowCache.h:129
xrpl::detail::BasicFullBelowCache::size
std::size_t size() const
Return the number of elements in the cache.
Definition
FullBelowCache.h:69
xrpl::detail::BasicFullBelowCache::ClockType
CacheType::ClockType ClockType
Definition
FullBelowCache.h:33
xrpl::detail::BasicFullBelowCache::clear
void clear()
Definition
FullBelowCache.h:122
xrpl::detail::BasicFullBelowCache::key_type
UInt256 key_type
Definition
FullBelowCache.h:32
xrpl::detail::BasicFullBelowCache::clock
ClockType & clock()
Return the clock associated with the cache.
Definition
FullBelowCache.h:58
xrpl::detail::BasicFullBelowCache::cache_
CacheType cache_
Definition
FullBelowCache.h:136
xrpl::detail::BasicFullBelowCache::BasicFullBelowCache
BasicFullBelowCache(std::string const &name, ClockType &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.
Definition
FullBelowCache.h:43
xrpl::detail::BasicFullBelowCache::getGeneration
std::uint32_t getGeneration() const
generation determines whether cached entry is valid
Definition
FullBelowCache.h:116
xrpl::detail::BasicFullBelowCache::CacheType
KeyCache CacheType
Definition
FullBelowCache.h:27
xrpl::detail::BasicFullBelowCache::insert
void insert(key_type const &key)
Insert a key into the cache.
Definition
FullBelowCache.h:107
cstddef
cstdint
std::chrono::seconds
std::uint32_t
xrpl::detail
Definition
base_uint.h:37
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::FullBelowCache
detail::BasicFullBelowCache FullBelowCache
Definition
FullBelowCache.h:142
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::KeyCache
TaggedCache< UInt256, int, true > KeyCache
Definition
KeyCache.h:8
std::size_t
string
Generated by
1.17.0