Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerCacheInterface.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 "data/Types.hpp"
23#include "etl/Models.hpp"
24
25#include <xrpl/basics/base_uint.h>
26#include <xrpl/basics/hardened_hash.h>
27
28#include <cstddef>
29#include <cstdint>
30#include <expected>
31#include <optional>
32#include <string>
33#include <vector>
34
35namespace data {
36
40class LedgerCacheInterface {
41public:
42 virtual ~LedgerCacheInterface() = default;
43 LedgerCacheInterface() = default;
44 LedgerCacheInterface(LedgerCacheInterface&&) = delete;
45 LedgerCacheInterface(LedgerCacheInterface const&) = delete;
46 LedgerCacheInterface&
47 operator=(LedgerCacheInterface&&) = delete;
48 LedgerCacheInterface&
49 operator=(LedgerCacheInterface const&) = delete;
50
58 virtual void
59 update(std::vector<LedgerObject> const& objs, uint32_t seq, bool isBackground = false) = 0;
60
67 virtual void
68 update(std::vector<etl::model::Object> const& objs, uint32_t seq) = 0;
69
77 virtual std::optional<Blob>
78 get(ripple::uint256 const& key, uint32_t seq) const = 0;
79
87 virtual std::optional<Blob>
88 getDeleted(ripple::uint256 const& key, uint32_t seq) const = 0;
89
99 virtual std::optional<LedgerObject>
100 getSuccessor(ripple::uint256 const& key, uint32_t seq) const = 0;
101
111 virtual std::optional<LedgerObject>
112 getPredecessor(ripple::uint256 const& key, uint32_t seq) const = 0;
113
117 virtual void
119
123 virtual bool
124 isDisabled() const = 0;
125
133 virtual void
134 setFull() = 0;
135
139 virtual uint32_t
141
145 virtual bool
146 isFull() const = 0;
147
151 virtual size_t
152 size() const = 0;
153
157 virtual float
158 getObjectHitRate() const = 0;
159
163 virtual float
165
171 virtual void
172 waitUntilCacheContainsSeq(uint32_t seq) = 0;
173
181 [[nodiscard]] virtual std::expected<void, std::string>
182 saveToFile(std::string const& path) const = 0;
183
192 [[nodiscard]] virtual std::expected<void, std::string>
193 loadFromFile(std::string const& path, uint32_t minLatestSequence) = 0;
194};
195
196} // 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 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 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:70