Woman, Life, Freedom


Adaptive AUTOSAR
ARA public interface header documentation
application::helper::MemoryCache< K, T > Class Template Reference

Memory cache helper class with expiration time. More...

#include <memory_cache.h>

Public Member Functions

 MemoryCache (std::chrono::seconds lifetime)
 Constructor. More...
 
void Add (K key, const T &item)
 Add an item to the cache. More...
 
bool TryGet (K key, T &item)
 Try to get an item from the cache. More...
 

Detailed Description

template<typename K, typename T>
class application::helper::MemoryCache< K, T >

Memory cache helper class with expiration time.

Template Parameters
KCache key type
TCached value type
Note
The class is not thread-safe.

Constructor & Destructor Documentation

◆ MemoryCache()

template<typename K , typename T >
application::helper::MemoryCache< K, T >::MemoryCache ( std::chrono::seconds  lifetime)
inlineexplicit

Constructor.

Parameters
lifetimeCached item lifetime in seconds

Member Function Documentation

◆ Add()

template<typename K , typename T >
void application::helper::MemoryCache< K, T >::Add ( key,
const T &  item 
)
inline

Add an item to the cache.

Parameters
keyItem cache key
itemItem to be cached

◆ TryGet()

template<typename K , typename T >
bool application::helper::MemoryCache< K, T >::TryGet ( key,
T &  item 
)
inline

Try to get an item from the cache.

Parameters
[in]keyItem cache key
[out]itemCached item
Returns
True if the item exists within the cache by the given key; otherwise false
Note
The 'item' argument will be untouched while returning 'false'.