23#include "util/BlockingCache.hpp"
25#include <boost/asio/spawn.hpp>
26#include <boost/json/array.hpp>
27#include <boost/json/object.hpp>
32#include <unordered_map>
33#include <unordered_set>
63 operator==(
Error const&)
const =
default;
69 std::chrono::steady_clock::duration cacheTimeout_;
70 std::unordered_map<std::string, std::unique_ptr<CacheEntry>> cache_;
80 std::chrono::steady_clock::duration cacheTimeout,
81 std::unordered_set<std::string>
const& cmds
112 [[nodiscard]] std::expected<boost::json::object, Error>
113 getOrUpdate(boost::asio::yield_context yield, std::string
const& cmd, Updater updater, Verifier verifier);
A thread-safe cache that blocks getting operations until the cache is updated.
Definition BlockingCache.hpp:50
std::function< std::expected< ValueType, ErrorType >(boost::asio::yield_context)> Updater
Function type for cache update operations.
Definition BlockingCache.hpp:87
std::function< bool(ValueType const &)> Verifier
Function type to verify if a value should be cached.
Definition BlockingCache.hpp:93
Cache of requests' responses with TTL support and configurable cachable commands.
Definition ResponseExpirationCache.hpp:45
void invalidate()
Invalidate all entries in the cache.
Definition ResponseExpirationCache.cpp:83
bool shouldCache(std::string const &cmd)
Check if the given command should be cached.
Definition ResponseExpirationCache.cpp:47
std::expected< boost::json::object, Error > getOrUpdate(boost::asio::yield_context yield, std::string const &cmd, Updater updater, Verifier verifier)
Get a cached response or update the cache if necessary.
Definition ResponseExpirationCache.cpp:53
ResponseExpirationCache(std::chrono::steady_clock::duration cacheTimeout, std::unordered_set< std::string > const &cmds)
Construct a new ResponseExpirationCache object.
Definition ResponseExpirationCache.cpp:35
This namespace contains various utilities.
Definition AccountUtils.hpp:30
A status returned from any RPC handler.
Definition Errors.hpp:82
A data structure to store a cache entry with its timestamp.
Definition ResponseExpirationCache.hpp:50
std::chrono::steady_clock::time_point lastUpdated
When the entry was last updated.
Definition ResponseExpirationCache.hpp:51
boost::json::object response
The cached response data.
Definition ResponseExpirationCache.hpp:52
A data structure to represent errors that can occur during an update of the cache.
Definition ResponseExpirationCache.hpp:58
boost::json::array warnings
Any warnings related to the request.
Definition ResponseExpirationCache.hpp:60
rpc::Status status
The status code and message of the error.
Definition ResponseExpirationCache.hpp:59