Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerCacheInterface.hpp
1#pragma once
2
3#include "data/Types.hpp"
4#include "etl/Models.hpp"
5
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/basics/hardened_hash.h>
8
9#include <cstddef>
10#include <cstdint>
11#include <expected>
12#include <optional>
13#include <string>
14#include <vector>
15
16namespace data {
17
21class LedgerCacheInterface {
22public:
23 virtual ~LedgerCacheInterface() = default;
24 LedgerCacheInterface() = default;
25 LedgerCacheInterface(LedgerCacheInterface&&) = delete;
26 LedgerCacheInterface(LedgerCacheInterface const&) = delete;
27 LedgerCacheInterface&
28 operator=(LedgerCacheInterface&&) = delete;
29 LedgerCacheInterface&
30 operator=(LedgerCacheInterface const&) = delete;
31
39 virtual void
40 update(std::vector<LedgerObject> const& objs, uint32_t seq, bool isBackground = false) = 0;
41
48 virtual void
49 update(std::vector<etl::model::Object> const& objs, uint32_t seq) = 0;
50
58 virtual std::optional<Blob>
59 get(ripple::uint256 const& key, uint32_t seq) const = 0;
60
68 virtual std::optional<Blob>
69 getDeleted(ripple::uint256 const& key, uint32_t seq) const = 0;
70
80 virtual std::optional<LedgerObject>
81 getSuccessor(ripple::uint256 const& key, uint32_t seq) const = 0;
82
92 virtual std::optional<LedgerObject>
93 getPredecessor(ripple::uint256 const& key, uint32_t seq) const = 0;
94
98 virtual void
100
104 virtual bool
105 isDisabled() const = 0;
106
114 virtual void
115 setFull() = 0;
116
120 virtual uint32_t
122
126 virtual bool
127 isFull() const = 0;
128
132 virtual size_t
133 size() const = 0;
134
139 virtual float
140 getObjectHitRate() const = 0;
141
146 virtual float
148
154 virtual void
155 waitUntilCacheContainsSeq(uint32_t seq) = 0;
156
164 [[nodiscard]] virtual std::expected<void, std::string>
165 saveToFile(std::string const& path) const = 0;
166
175 [[nodiscard]] virtual std::expected<void, std::string>
176 loadFromFile(std::string const& path, uint32_t minLatestSequence) = 0;
177
183 virtual void
185
190 [[nodiscard]] virtual bool
192};
193
194} // namespace data
virtual std::optional< LedgerObject > getPredecessor(ripple::uint256 const &key, uint32_t seq) const =0
Gets a cached predcessor.
virtual std::expected< void, std::string > saveToFile(std::string const &path) const =0
Save the cache to file.
virtual bool isFull() const =0
virtual float getObjectHitRate() const =0
virtual void update(std::vector< LedgerObject > const &objs, uint32_t seq, bool isBackground=false)=0
Update the cache with new ledger objects.
virtual bool isDisabled() const =0
virtual void setDisabled()=0
Disables the cache.
virtual void setFull()=0
Sets the full flag to true.
virtual std::optional< Blob > get(ripple::uint256 const &key, uint32_t seq) const =0
Fetch a cached object by its key and sequence number.
virtual size_t size() const =0
virtual std::optional< LedgerObject > getSuccessor(ripple::uint256 const &key, uint32_t seq) const =0
Gets a cached successor.
virtual void update(std::vector< etl::model::Object > const &objs, uint32_t seq)=0
Update the cache with new ledger objects.
virtual bool isCurrentlyLoading() const =0
Check whether the cache is currently being loaded from the backend.
virtual void waitUntilCacheContainsSeq(uint32_t seq)=0
Waits until the cache contains a specific sequence.
virtual std::optional< Blob > getDeleted(ripple::uint256 const &key, uint32_t seq) const =0
Fetch a recently deleted object by its key and sequence number.
virtual float getSuccessorHitRate() const =0
virtual void startLoading()=0
Mark the cache as currently loading from the backend.
virtual std::expected< void, std::string > loadFromFile(std::string const &path, uint32_t minLatestSequence)=0
Load the cache from file.
virtual uint32_t latestLedgerSequence() const =0
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56