rippled
Loading...
Searching...
No Matches
FullBelowCache.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_SHAMAP_FULLBELOWCACHE_H_INCLUDED
21#define RIPPLE_SHAMAP_FULLBELOWCACHE_H_INCLUDED
22
23#include <xrpl/basics/KeyCache.h>
24#include <xrpl/basics/TaggedCache.h>
25#include <xrpl/basics/base_uint.h>
26#include <xrpl/beast/insight/Collector.h>
27#include <xrpl/beast/utility/Journal.h>
28#include <atomic>
29#include <string>
30
31namespace ripple {
32
33namespace detail {
34
39{
40private:
42
43public:
45
48
57 std::string const& name,
60 beast::insight::Collector::ptr const& collector =
64 : m_cache(name, target_size, expiration, clock, j, collector), m_gen(1)
65 {
66 }
67
71 {
72 return m_cache.clock();
73 }
74
80 size() const
81 {
82 return m_cache.size();
83 }
84
89 void
91 {
92 m_cache.sweep();
93 }
94
101 bool
103 {
104 return m_cache.touch_if_exists(key);
105 }
106
114 void
115 insert(key_type const& key)
116 {
117 m_cache.insert(key);
118 }
119
122 getGeneration(void) const
123 {
124 return m_gen;
125 }
126
127 void
129 {
130 m_cache.clear();
131 ++m_gen;
132 }
133
134 void
136 {
137 m_cache.clear();
138 m_gen = 1;
139 }
140
141private:
144};
145
146} // namespace detail
147
149
150} // namespace ripple
151
152#endif
A generic endpoint for log messages.
Definition: Journal.h:59
static std::shared_ptr< Collector > New()
Map/cache combination.
Definition: TaggedCache.h:57
auto insert(key_type const &key, T const &value) -> std::enable_if_t<!IsKeyCache, ReturnType >
Insert the element into the container.
Definition: TaggedCache.h:411
bool touch_if_exists(KeyComparable const &key)
Refresh the last access time on a key if present.
Definition: TaggedCache.h:185
clock_type & clock()
Return the clock associated with the cache.
Definition: TaggedCache.h:91
beast::abstract_clock< std::chrono::steady_clock > clock_type
Definition: TaggedCache.h:62
std::size_t size() const
Returns the number of items in the container.
Definition: TaggedCache.h:98
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:26
base_uint< 256 > uint256
Definition: base_uint.h:557
TaggedCache< uint256, int, true > KeyCache
Definition: KeyCache.h:28