Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerCacheSaver.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/LedgerCacheInterface.hpp"
23#include "util/config/ConfigDefinition.hpp"
24
25#include <concepts>
26#include <functional>
27#include <optional>
28#include <string>
29#include <thread>
30
31namespace data {
32
39template <typename T>
40concept SomeLedgerCacheSaver = requires(T a) {
41 { a.save() } -> std::same_as<void>;
42 { a.waitToFinish() } -> std::same_as<void>;
43};
44
53 std::optional<std::string> cacheFilePath_;
54 std::reference_wrapper<LedgerCacheInterface const> cache_;
55 std::optional<std::thread> savingThread_;
56
57public:
65
72
80 void
81 save();
82
89 void
91};
92
93} // namespace data
Cache for an entire ledger.
Definition LedgerCacheInterface.hpp:40
~LedgerCacheSaver()
Destructor that ensures the saving thread is properly joined.
Definition LedgerCacheSaver.cpp:37
LedgerCacheSaver(util::config::ClioConfigDefinition const &config, LedgerCacheInterface const &cache)
Constructs a LedgerCacheSaver instance.
Definition LedgerCacheSaver.cpp:32
void waitToFinish()
Waits for the saving thread to complete.
Definition LedgerCacheSaver.cpp:62
void save()
Initiates an asynchronous save operation of the ledger cache.
Definition LedgerCacheSaver.cpp:43
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:50
A concept for a class that can save ledger cache asynchronously.
Definition LedgerCacheSaver.hpp:40
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70