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
29#include <atomic>
30#include <string>
31
32namespace ripple {
33
34namespace detail {
35
40{
41private:
43
44public:
46
49
58 std::string const& name,
61 beast::insight::Collector::ptr const& collector =
65 : m_cache(name, target_size, expiration, clock, j, collector), m_gen(1)
66 {
67 }
68
72 {
73 return m_cache.clock();
74 }
75
81 size() const
82 {
83 return m_cache.size();
84 }
85
90 void
92 {
93 m_cache.sweep();
94 }
95
102 bool
104 {
105 return m_cache.touch_if_exists(key);
106 }
107
115 void
116 insert(key_type const& key)
117 {
118 m_cache.insert(key);
119 }
120
123 getGeneration(void) const
124 {
125 return m_gen;
126 }
127
128 void
130 {
131 m_cache.clear();
132 ++m_gen;
133 }
134
135 void
137 {
138 m_cache.clear();
139 m_gen = 1;
140 }
141
142private:
145};
146
147} // namespace detail
148
150
151} // namespace ripple
152
153#endif
A generic endpoint for log messages.
Definition Journal.h:60
static std::shared_ptr< Collector > New()
Map/cache combination.
Definition TaggedCache.h:62
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:67
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:25
base_uint< 256 > uint256
Definition base_uint.h:558
TaggedCache< uint256, int, true > KeyCache
Definition KeyCache.h:28