Sirius  0.0.0
Public Member Functions | List of all members
sirius::utils::LRUCache< Key, Value, CacheSize > Class Template Reference

LRU cache. More...

#include <sirius/utils/lru_cache.h>

Public Member Functions

 LRUCache ()=default
 
 ~LRUCache ()=default
 
 LRUCache (const LRUCache &)=delete
 
LRUCacheoperator= (const LRUCache &)=delete
 
 LRUCache (LRUCache &&)=delete
 
LRUCacheoperator= (LRUCache &&)=delete
 
Value Get (const Key &key)
 Get a cache element. More...
 
void Insert (const Key &key, Value element)
 Insert an element in the cache. More...
 
void Remove (const Key &key)
 Remove an element from the cache. More...
 
void Clear ()
 Clear all the cache elements. More...
 
bool Contains (const Key &key) const
 Check that a particular key is present in cache. More...
 
std::size_t Size ()
 Get the current size of the cache. More...
 

Detailed Description

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

LRU cache.

Constructor & Destructor Documentation

◆ LRUCache() [1/3]

template<typename Key, typename Value, std::size_t CacheSize = 5>
sirius::utils::LRUCache< Key, Value, CacheSize >::LRUCache ( )
default

◆ ~LRUCache()

template<typename Key, typename Value, std::size_t CacheSize = 5>
sirius::utils::LRUCache< Key, Value, CacheSize >::~LRUCache ( )
default

◆ LRUCache() [2/3]

template<typename Key, typename Value, std::size_t CacheSize = 5>
sirius::utils::LRUCache< Key, Value, CacheSize >::LRUCache ( const LRUCache< Key, Value, CacheSize > &  )
delete

◆ LRUCache() [3/3]

template<typename Key, typename Value, std::size_t CacheSize = 5>
sirius::utils::LRUCache< Key, Value, CacheSize >::LRUCache ( LRUCache< Key, Value, CacheSize > &&  )
delete

Member Function Documentation

◆ Clear()

template<typename Key, typename Value, std::size_t CacheSize = 5>
void sirius::utils::LRUCache< Key, Value, CacheSize >::Clear ( )
inline

Clear all the cache elements.

◆ Contains()

template<typename Key, typename Value, std::size_t CacheSize = 5>
bool sirius::utils::LRUCache< Key, Value, CacheSize >::Contains ( const Key &  key) const
inline

Check that a particular key is present in cache.

Parameters
keykey of the requested element
Returns
true if the element is present in cache

◆ Get()

template<typename Key, typename Value, std::size_t CacheSize = 5>
Value sirius::utils::LRUCache< Key, Value, CacheSize >::Get ( const Key &  key)
inline

Get a cache element.

The element fetched will be the new head of the cache

Parameters
keykey of the requested element
Returns
cache element if exists or default constructed element if not

◆ Insert()

template<typename Key, typename Value, std::size_t CacheSize = 5>
void sirius::utils::LRUCache< Key, Value, CacheSize >::Insert ( const Key &  key,
Value  element 
)
inline

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
keykey of the element
elementelement to insert

◆ operator=() [1/2]

template<typename Key, typename Value, std::size_t CacheSize = 5>
LRUCache& sirius::utils::LRUCache< Key, Value, CacheSize >::operator= ( const LRUCache< Key, Value, CacheSize > &  )
delete

◆ operator=() [2/2]

template<typename Key, typename Value, std::size_t CacheSize = 5>
LRUCache& sirius::utils::LRUCache< Key, Value, CacheSize >::operator= ( LRUCache< Key, Value, CacheSize > &&  )
delete

◆ Remove()

template<typename Key, typename Value, std::size_t CacheSize = 5>
void sirius::utils::LRUCache< Key, Value, CacheSize >::Remove ( const Key &  key)
inline

Remove an element from the cache.

Parameters
keykey of the element

◆ Size()

template<typename Key, typename Value, std::size_t CacheSize = 5>
std::size_t sirius::utils::LRUCache< Key, Value, CacheSize >::Size ( )
inline

Get the current size of the cache.

Returns
size of the cache

The documentation for this class was generated from the following file: