Class CacheManager

Nested Relationships

Nested Types

Class Documentation

class CacheManager

This class implements a cache manager useful for the cases when the number of times the cached objects will be accessed is known.

Public Types

using key_type = size_t

Public Functions

template<typename Iterable1 = container::map<size_t, size_t>>
inline explicit CacheManager(Iterable1 &&decaying) noexcept
void reset() noexcept

Resets all cached data.

ERPtr access(key_type key) noexcept

Access cached data.

Parameters:

key – The that identifies the cached data.

Returns:

ERPtr to EvalResult

ERPtr store(key_type key, ERPtr data) noexcept
Parameters:
  • key – The key to identify the cached data.

  • data – The data to be cached.

Returns:

Pointer to the stored data. Implictly accesses the stored data, hence, decays the lifetime if the key accesses a decaying cache entry. Passing key that was not present during construction of this CacheManager object, stores nothing, but still returns a valid pointer to data.

bool exists(key_type key) const noexcept

Check if the key exists in the database: does not check if cache exists.

int life(key_type key) const noexcept

if the key exists in the database, return the current lifetime count of the cached data otherwise return -1

int max_life(key_type key) const noexcept

if the key exists in the database, return the maximum lifetime count of the cached data that implies the maximum number of accesses allowed for this key before the cache is released. This value was set by the c’tor.

container::set<size_t> keys() const noexcept
Returns:

A set of all the keys present in the cache manager.

Public Static Functions

static CacheManager empty() noexcept

Get an empty cache manager.

Friends

friend struct access_by
template<typename T>
struct access_by