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) const
 Get a response from the cache.
 
void put (std::string const &cmd, 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) const
nodiscard

Get a response from the cache.

Parameters
cmdThe command to get the response for
Returns
The response if it exists or std::nullopt otherwise

◆ put()

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

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

Parameters
cmdThe command to store the response for
responseThe response to store

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