Class CacheManager¶
Defined in File cache_manager.hpp
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.
-
ResultPtr access(key_type key) noexcept¶
Access cached data.
- Parameters:
key – The that identifies the cached data.
- Returns:
ResultPtr to Result
-
ResultPtr store(key_type key, ResultPtr 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
keythat was not present during construction of this CacheManager object, stores nothing, but still returns a valid pointer todata.
-
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.
-
size_t alive_count() const noexcept¶
- Returns:
The number of entries with life_count greater than zero.
-
size_t size_in_bytes() const noexcept¶
- Returns:
Returns the sum of
Result::size_in_bytesof alive entries.
Public Static Functions
-
static CacheManager empty() noexcept¶
Get an empty cache manager.
Friends
- friend struct access_by
-
template<typename T>
struct access_by¶
-
using key_type = size_t¶