1919
2020#pragma once
2121
22+ #include " data/LedgerCacheInterface.hpp"
2223#include " data/Types.hpp"
2324#include " util/prometheus/Counter.hpp"
2425#include " util/prometheus/Label.hpp"
@@ -43,7 +44,7 @@ namespace data {
4344/* *
4445 * @brief Cache for an entire ledger.
4546 */
46- class LedgerCache {
47+ class LedgerCache : public LedgerCacheInterface {
4748 struct CacheEntry {
4849 uint32_t seq = 0 ;
4950 Blob blob;
@@ -83,109 +84,44 @@ class LedgerCache {
8384 std::unordered_set<ripple::uint256, ripple::hardened_hash<>> deletes_;
8485
8586public:
86- /* *
87- * @brief Update the cache with new ledger objects.
88- *
89- * @param objs The ledger objects to update cache with
90- * @param seq The sequence to update cache for
91- * @param isBackground Should be set to true when writing old data from a background thread
92- */
9387 void
94- update (std::vector<LedgerObject> const & objs, uint32_t seq, bool isBackground = false );
95-
96- /* *
97- * @brief Fetch a cached object by its key and sequence number.
98- *
99- * @param key The key to fetch for
100- * @param seq The sequence to fetch for
101- * @return If found in cache, will return the cached Blob; otherwise nullopt is returned
102- */
88+ update (std::vector<LedgerObject> const & objs, uint32_t seq, bool isBackground = false ) override ;
89+
10390 std::optional<Blob>
104- get (ripple::uint256 const & key, uint32_t seq) const ;
105-
106- /* *
107- * @brief Gets a cached successor.
108- *
109- * Note: This function always returns std::nullopt when @ref isFull() returns false.
110- *
111- * @param key The key to fetch for
112- * @param seq The sequence to fetch for
113- * @return If found in cache, will return the cached successor; otherwise nullopt is returned
114- */
91+ get (ripple::uint256 const & key, uint32_t seq) const override ;
92+
11593 std::optional<LedgerObject>
116- getSuccessor (ripple::uint256 const & key, uint32_t seq) const ;
117-
118- /* *
119- * @brief Gets a cached predcessor.
120- *
121- * Note: This function always returns std::nullopt when @ref isFull() returns false.
122- *
123- * @param key The key to fetch for
124- * @param seq The sequence to fetch for
125- * @return If found in cache, will return the cached predcessor; otherwise nullopt is returned
126- */
94+ getSuccessor (ripple::uint256 const & key, uint32_t seq) const override ;
95+
12796 std::optional<LedgerObject>
128- getPredecessor (ripple::uint256 const & key, uint32_t seq) const ;
97+ getPredecessor (ripple::uint256 const & key, uint32_t seq) const override ;
12998
130- /* *
131- * @brief Disables the cache.
132- */
13399 void
134- setDisabled ();
100+ setDisabled () override ;
135101
136- /* *
137- * @return true if the cache is disabled; false otherwise
138- */
139102 bool
140- isDisabled () const ;
141-
142- /* *
143- * @brief Sets the full flag to true.
144- *
145- * This is used when cache loaded in its entirety at startup of the application. This can be either loaded from DB,
146- * populated together with initial ledger download (on first run) or downloaded from a peer node (specified in
147- * config).
148- */
103+ isDisabled () const override ;
104+
149105 void
150- setFull ();
106+ setFull () override ;
151107
152- /* *
153- * @return The latest ledger sequence for which cache is available.
154- */
155108 uint32_t
156- latestLedgerSequence () const ;
109+ latestLedgerSequence () const override ;
157110
158- /* *
159- * @return true if the cache has all data for the most recent ledger; false otherwise
160- */
161111 bool
162- isFull () const ;
112+ isFull () const override ;
163113
164- /* *
165- * @return The total size of the cache.
166- */
167114 size_t
168- size () const ;
115+ size () const override ;
169116
170- /* *
171- * @return A number representing the success rate of hitting an object in the cache versus missing it.
172- */
173117 float
174- getObjectHitRate () const ;
118+ getObjectHitRate () const override ;
175119
176- /* *
177- * @return A number representing the success rate of hitting a successor in the cache versus missing it.
178- */
179120 float
180- getSuccessorHitRate () const ;
121+ getSuccessorHitRate () const override ;
181122
182- /* *
183- * @brief Waits until the cache contains a specific sequence.
184- *
185- * @param seq The sequence to wait for
186- */
187123 void
188- waitUntilCacheContainsSeq (uint32_t seq);
124+ waitUntilCacheContainsSeq (uint32_t seq) override ;
189125};
190126
191127} // namespace data
0 commit comments