Clio
develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerHeaderCache.hpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of clio: https://github.com/XRPLF/clio
4
Copyright (c) 2025, the clio developers.
5
6
Permission to use, copy, modify, and 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
#pragma once
21
22
#include "util/Mutex.hpp"
23
24
#include <xrpl/protocol/LedgerHeader.h>
25
26
#include <cstdint>
27
#include <optional>
28
#include <shared_mutex>
29
30
namespace
data
{
31
41
class
FetchLedgerCache
{
42
public
:
43
FetchLedgerCache
();
44
48
struct
CacheEntry
{
49
ripple::LedgerHeader ledger;
50
uint32_t seq{};
51
58
bool
59
operator==
(
CacheEntry
const
& other)
const
60
{
61
return
ledger.hash == other.ledger.hash && seq == other.seq;
62
}
63
};
64
70
void
71
put
(CacheEntry
const
& cacheEntry);
72
78
std::optional<CacheEntry>
79
get
()
const
;
80
81
private
:
82
mutable
util::Mutex<std::optional<CacheEntry>
, std::shared_mutex> mutex_;
83
};
84
85
}
// namespace data
data::FetchLedgerCache
A simple cache holding one ripple::LedgerHeader to reduce DB lookups.
Definition
LedgerHeaderCache.hpp:41
data::FetchLedgerCache::put
void put(CacheEntry const &cacheEntry)
Put CacheEntry into thread-safe container.
Definition
LedgerHeaderCache.cpp:33
data::FetchLedgerCache::get
std::optional< CacheEntry > get() const
Read CacheEntry from thread-safe container.
Definition
LedgerHeaderCache.cpp:40
util::Mutex
A container for data that is protected by a mutex. Inspired by Mutex in Rust.
Definition
Mutex.hpp:96
data
This namespace implements the data access layer and related components.
Definition
AmendmentCenter.cpp:70
data::FetchLedgerCache::CacheEntry
Struct to store ledger header cache entry and the sequence it belongs to.
Definition
LedgerHeaderCache.hpp:48
data::FetchLedgerCache::CacheEntry::operator==
bool operator==(CacheEntry const &other) const
Comparing CacheEntry. Used in testing for EXPECT_CALL.
Definition
LedgerHeaderCache.hpp:59
src
data
LedgerHeaderCache.hpp
Generated by
1.12.0