Clio develop
The XRP Ledger API server.
|
A thread-safe cache that blocks getting operations until the cache is updated. More...
#include <BlockingCache.hpp>
Public Types | |
enum class | State { NoValue , Updating , HasValue } |
Possible states of the cache. | |
using | Updater = std::function<std::expected<ValueType, ErrorType>(boost::asio::yield_context)> |
Function type for cache update operations. | |
using | Verifier = std::function<bool(ValueType const&)> |
Function type to verify if a value should be cached. | |
Public Member Functions | |
BlockingCache ()=default | |
Default constructor - creates an empty cache. | |
BlockingCache (ValueType initialValue) | |
Construct a cache with an initial value. | |
BlockingCache (BlockingCache &&)=delete | |
BlockingCache (BlockingCache const &)=delete | |
BlockingCache & | operator= (BlockingCache &&)=delete |
BlockingCache & | operator= (BlockingCache const &)=delete |
std::expected< ValueType, ErrorType > | asyncGet (boost::asio::yield_context yield, Updater updater, Verifier verifier) |
Asynchronously get a value from the cache, updating if necessary. | |
std::expected< ValueType, ErrorType > | update (boost::asio::yield_context yield, Updater updater, Verifier verifier) |
Force an update of the cache value. | |
void | invalidate () |
Invalidates the currently cached value if present. | |
State | state () const |
Returns the current state of the cache. | |
A thread-safe cache that blocks getting operations until the cache is updated.
ValueType | The type of value to be cached |
ErrorType | The type of error that can occur during updates |
using util::BlockingCache< ValueType, ErrorType >::Updater = std::function<std::expected<ValueType, ErrorType>(boost::asio::yield_context)> |
Function type for cache update operations.
Called when the cache needs to be populated or refreshed
using util::BlockingCache< ValueType, ErrorType >::Verifier = std::function<bool(ValueType const&)> |
Function type to verify if a value should be cached.
Returns true if the value should be stored in the cache
|
inlineexplicit |
Construct a cache with an initial value.
initialValue | The value to initialize the cache with |
|
inlinenodiscard |
Asynchronously get a value from the cache, updating if necessary.
yield | The asio yield context for coroutine suspension |
updater | Function to generate a new value if needed |
verifier | Function to validate whether a value should be cached |
Depending on the current cache state, this will either:
|
inline |
Invalidates the currently cached value if present.
Clears the cache and sets its state to Empty. Has no effect if the cache is already empty or being updated.
|
inlinenodiscard |
Returns the current state of the cache.
|
inlinenodiscard |
Force an update of the cache value.
yield | The ASIO yield context for coroutine suspension |
updater | Function to generate a new value |
verifier | Function to validate whether a value should be cached |
Initiates a cache update operation regardless of current state. If another update is already in progress, waits for it to complete.