cvedia::rt::TimedCache¶
A thread-safe cache whose entries expire after a per-entry timeout. More...
#include <timed_cache.h>
Public Types¶
| Name | |
|---|---|
| using std::chrono::steady_clock | Clock |
Public Functions¶
| Name | |
|---|---|
| TimedCache(bool autocleanUp =false, std::chrono::seconds cleanUpPeriod =std::chrono::seconds(60), std::chrono::seconds defaultTimeout =std::chrono::seconds(60)) | |
| ~TimedCache() | |
| void | insert(const Key_t & key, const Value_t & value) |
| void | insert(const Key_t & key, const Value_t & value, std::chrono::seconds timeout) |
| expected< Value_t > | get(const Key_t & key) const |
| Value_t | get(const Key_t & key, const Value_t & valueIfNotExists) const |
| expected< Value_t > | getWithKeepAlive(const Key_t & key, std::chrono::seconds keepAliveFor) |
| Value_t | getWithKeepAlive(const Key_t & key, std::chrono::seconds keepAliveFor, const Value_t & valueIfNotExists) |
| void | cleanUp() |
| std::size_t | size() const |
Detailed Description¶
template <typename Key_t ,
typename Value_t >
class cvedia::rt::TimedCache;
A thread-safe cache whose entries expire after a per-entry timeout.
Expired entries are never served: every read checks the entry's deadline, so the staleness of a served value is bounded by its timeout regardless of when the expired entry is physically reclaimed. Reclamation happens lazily on every insert(), explicitly via cleanUp(), or periodically through the optional clean-up thread.
Expiry is measured on the steady clock, so wall-clock adjustments (NTP, manual changes) do not extend or shorten entry lifetimes.
Public Types Documentation¶
using Clock¶
using Clock = std::chrono::steady_clock;
Public Functions Documentation¶
function TimedCache¶
inline TimedCache(
bool autocleanUp =false,
std::chrono::seconds cleanUpPeriod =std::chrono::seconds(60),
std::chrono::seconds defaultTimeout =std::chrono::seconds(60)
)
function ~TimedCache¶
inline ~TimedCache()
function insert¶
inline void insert(
const Key_t & key,
const Value_t & value
)
function insert¶
inline void insert(
const Key_t & key,
const Value_t & value,
std::chrono::seconds timeout
)
function get¶
inline expected< Value_t > get(
const Key_t & key
) const
function get¶
inline Value_t get(
const Key_t & key,
const Value_t & valueIfNotExists
) const
function getWithKeepAlive¶
inline expected< Value_t > getWithKeepAlive(
const Key_t & key,
std::chrono::seconds keepAliveFor
)
function getWithKeepAlive¶
inline Value_t getWithKeepAlive(
const Key_t & key,
std::chrono::seconds keepAliveFor,
const Value_t & valueIfNotExists
)
function cleanUp¶
inline void cleanUp()
function size¶
inline std::size_t size() const