3.3.2.30. Template Class LRUCache

3.3.2.30.1. Class Documentation

template <typename Key, typename Value, std::size_t CacheSize = 5>
class LRUCache

LRU cache.

Public Functions

LRUCache()
~LRUCache()
LRUCache(const LRUCache&)
LRUCache &operator=(const LRUCache&)
LRUCache(LRUCache&&)
LRUCache &operator=(LRUCache&&)
Value Get(const Key &key)

Get a cache element.

The element fetched will be the new head of the cache

Return
cache element if exists or default constructed element if not
Parameters
  • key: key of the requested element

void Insert(const Key &key, Value element)

Insert an element in the cache.

If the cache size reaches the max size, the last recently used (LRU) element is removed from the cache

Parameters
  • key: key of the element
  • element: element to insert

void Remove(const Key &key)

Remove an element from the cache.

Parameters
  • key: key of the element

void Clear()

Clear all the cache elements.

bool Contains(const Key &key) const

Check that a particular key is present in cache.

Return
true if the element is present in cache
Parameters
  • key: key of the requested element

std::size_t Size()

Get the current size of the cache.

Return
size of the cache