Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerHeaderCache.hpp
1#pragma once
2
3#include "util/Mutex.hpp"
4
5#include <xrpl/protocol/LedgerHeader.h>
6
7#include <cstdint>
8#include <optional>
9#include <shared_mutex>
10
11namespace data {
12
22class FetchLedgerCache {
23public:
24 FetchLedgerCache();
25
29 struct CacheEntry {
30 ripple::LedgerHeader ledger;
31 uint32_t seq{};
32
39 bool
40 operator==(CacheEntry const& other) const
41 {
42 return ledger.hash == other.ledger.hash && seq == other.seq;
43 }
44 };
45
51 void
52 put(CacheEntry const& cacheEntry);
53
59 std::optional<CacheEntry>
60 get() const;
61
62private:
63 mutable util::Mutex<std::optional<CacheEntry>, std::shared_mutex> mutex_;
64};
65
66} // namespace data
void put(CacheEntry const &cacheEntry)
Put CacheEntry into thread-safe container.
Definition LedgerHeaderCache.cpp:14
std::optional< CacheEntry > get() const
Read CacheEntry from thread-safe container.
Definition LedgerHeaderCache.cpp:21
A container for data that is protected by a mutex. Inspired by Mutex in Rust.
Definition Mutex.hpp:82
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
Struct to store ledger header cache entry and the sequence it belongs to.
Definition LedgerHeaderCache.hpp:29
bool operator==(CacheEntry const &other) const
Comparing CacheEntry. Used in testing for EXPECT_CALL.
Definition LedgerHeaderCache.hpp:40