Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util::ResponseExpirationCache Class Reference

Cache of requests' responses with TTL support and configurable cacheable commands. More...

#include <ResponseExpirationCache.hpp>

Public Member Functions

 ResponseExpirationCache (std::chrono::steady_clock::duration cacheTimeout, std::unordered_set< std::string > const &cmds)
 Construct a new Cache object.
std::optional< boost::json::object > get (std::string const &cmd, boost::json::object const &request) const
 Get a response from the cache.
void put (std::string const &cmd, boost::json::object const &request, boost::json::object const &response)
 Put a response into the cache if the request should be cached.
void invalidate ()
 Invalidate all entries in the cache.

Detailed Description

Cache of requests' responses with TTL support and configurable cacheable commands.

Constructor & Destructor Documentation

◆ ResponseExpirationCache()

util::ResponseExpirationCache::ResponseExpirationCache ( std::chrono::steady_clock::duration cacheTimeout,
std::unordered_set< std::string > const & cmds )
inline

Construct a new Cache object.

Parameters
cacheTimeoutThe time for cache entries to expire
cmdsThe commands that should be cached

Member Function Documentation

◆ get()

std::optional< boost::json::object > util::ResponseExpirationCache::get ( std::string const & cmd,
boost::json::object const & request ) const
nodiscard

Get a response from the cache.

Only bare requests (those carrying no response-customizing params beyond "command", "method", and "id") are served from the cache. Non-bare requests always return std::nullopt.

Parameters
cmdThe command to get the response for
requestThe full request object; used to determine whether the request is bare
Returns
The cached response if available and not expired, or std::nullopt otherwise

◆ put()

void util::ResponseExpirationCache::put ( std::string const & cmd,
boost::json::object const & request,
boost::json::object const & response )

Put a response into the cache if the request should be cached.

Only bare requests (those carrying no response-customizing params beyond "command", "method", and "id") are stored in the cache. Non-bare requests are silently ignored.

Parameters
cmdThe command to store the response for
requestThe full request object; used to determine whether the request is bare
responseThe response to store

The documentation for this class was generated from the following files: