template<typename K, typename V>
eckit::CacheLRU class

Public types

struct Entry
using key_type = K
using value_type = V
using entry_type = Entry
using storage_type = std::list<entry_type>
using storage_iterator = storage_type::iterator
using map_type = std::map<key_type, storage_iterator>
using purge_handler_type = void(*)(key_type&, value_type&)

Constructors, destructors, conversion operators

CacheLRU(size_t capacity, purge_handler_type purge = 0)
~CacheLRU()

Public functions

auto insert(const key_type& key, const value_type& value) -> bool
auto access(const key_type& key) -> value_type
auto extract(const key_type& key) -> value_type
auto remove(const key_type& key) -> bool
auto exists(const key_type& key) const -> bool
void clear()
Clears all entries in the cache.
auto capacity() const -> size_t
auto size() const -> size_t
void capacity(size_t size)
resizes the cache capacity
void print(std::ostream& os) const

Friends

auto operator<<(std::ostream& s, const CacheLRU& p) -> std::ostream&

Function documentation

template<typename K, typename V>
bool eckit::CacheLRU<K, V>::insert(const key_type& key, const value_type& value)

Returns true if a key already existed

Inserts an entry into the cache, overwrites if already exists

template<typename K, typename V>
value_type eckit::CacheLRU<K, V>::access(const key_type& key)

Exceptions
OutOfRange exception is key not in cache

Accesses a key that must already exist

template<typename K, typename V>
value_type eckit::CacheLRU<K, V>::extract(const key_type& key)

Exceptions
OutOfRange exception if key not in cache

Extracts the key from the cache without purging

template<typename K, typename V>
bool eckit::CacheLRU<K, V>::remove(const key_type& key)

Returns true if removed

Remove a key-value pair from the cache No effect if key is not present

template<typename K, typename V>
bool eckit::CacheLRU<K, V>::exists(const key_type& key) const

Returns true if the key exists in the cache

template<typename K, typename V>
size_t eckit::CacheLRU<K, V>::capacity() const

Returns the maximum size of the cache

template<typename K, typename V>
size_t eckit::CacheLRU<K, V>::size() const

Returns the current (used) size of the cache
This website is beyond its original expiry date and the content may be out of date. The site owner has been notified and may choose to extend the expiry date and remove this banner. If you have any questions about this, please visit our support portal.