ark::core::KeyValueCache

Defined in header “ark/core/key_value_cache.hh”.


A simple key/value cache with byte-based capacity control. Keys are std::string and values are ark::core::ByteBuffer. Each entry tracks the last time it was retrieved/stored and the number of retrievals to influence eviction decisions.

Typedefs

  • using AbstractValuePtr = std::shared_ptr< AbstractValue >
    Shared pointer used for the implementation of the value.

Methods

  • KeyValueCache(const KeyValueCacheConfig & config)
    Constructor that fixes the cache configuration for this instance.

  • AbstractValuePtr get(const std::string & key)
    Returns the cached value for the given key if present; otherwise returns an empty pointer. If present, this updates the entry’s last-access time and increments the retrieval count.

  • void put(const std::string & key, const AbstractValuePtr & value)
    Stores a key/value pair into the cache. The “last time data was retrieved” field is initialized to now, and the retrieval count is initialized to zero.

    If the value’s size exceeds the configured capacity by itself, this throws.

  • void clear()
    Removes all entries from the cache and resets its accounting.

  • std::size_t total_value_size()
    Returns the total number of bytes stored across all values (not counting keys).

  • std::size_t item_count()
    Returns the number of items stored.

  • KeyValueCacheConfig config()
    Returns the active configuration for this cache.

  • std::optional< std::size_t > retrieval_count_for(const std::string & key)
    Returns the number of times the given key has been retrieved so far, or empty if the key does not exist.

  • std::optional< std::chrono::steady_clock::time_point > last_access_for(const std::string & key)
    Returns the last-access time for the given key, or empty if the key does not exist.