AWS SDK for C++

AWS SDK for C++ Version 1.11.791

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
Aws::Utils::Cache< TKey, TValue > Class Template Reference

#include <Cache.h>

Classes

struct  Value
 

Public Types

using TransformFunction = std::function< Value(const TKey &, Value &)>
 
using FilterFunction = std::function< bool(const TKey &, const Value &)>
 

Public Member Functions

 Cache (size_t initialSize=1000)
 
bool Get (const TKey &key, TValue &value) const
 
template<typename UValue >
void Put (TKey &&key, UValue &&val, std::chrono::milliseconds duration)
 
template<typename UValue >
void Put (const TKey &key, UValue &&val, std::chrono::milliseconds duration)
 
void Transform (TransformFunction function)
 
void Filter (FilterFunction function)
 

Detailed Description

template<typename TKey, typename TValue>
class Aws::Utils::Cache< TKey, TValue >

In-memory fixed-size cache utility.

Definition at line 20 of file Cache.h.

Member Typedef Documentation

◆ FilterFunction

template<typename TKey , typename TValue >
using Aws::Utils::Cache< TKey, TValue >::FilterFunction = std::function<bool(const TKey &, const Value&)>

Will remove a entry from the map base on a function applied on the value of the entry. If true the entry will be remove from the cache.

Parameters
functionThe predicate that will determine if a value is removed.

Definition at line 130 of file Cache.h.

◆ TransformFunction

template<typename TKey , typename TValue >
using Aws::Utils::Cache< TKey, TValue >::TransformFunction = std::function<Value(const TKey &, Value &)>

Will transform the underlying cache to have a updated Value from the result of a function.

Parameters
functionA function that returns type value that will be inserted into the cache at the specified key.

Definition at line 117 of file Cache.h.

Constructor & Destructor Documentation

◆ Cache()

template<typename TKey , typename TValue >
Aws::Utils::Cache< TKey, TValue >::Cache ( size_t  initialSize = 1000)
inlineexplicit

Initialize the cache with a particular size. The size of the cache is fixed and does not grow over time.

Definition at line 27 of file Cache.h.

Member Function Documentation

◆ Filter()

template<typename TKey , typename TValue >
void Aws::Utils::Cache< TKey, TValue >::Filter ( FilterFunction  function)
inline

Definition at line 131 of file Cache.h.

◆ Get()

template<typename TKey , typename TValue >
bool Aws::Utils::Cache< TKey, TValue >::Get ( const TKey &  key,
TValue &  value 
) const
inline

Retrieves the value associated with the given key if exists and returns true. Otherwise, returns false.

Parameters
keyThe of key of the entry to retrieve.
valueThe retrieved value in case the key exists in the cache

Definition at line 42 of file Cache.h.

◆ Put() [1/2]

template<typename TKey , typename TValue >
template<typename UValue >
void Aws::Utils::Cache< TKey, TValue >::Put ( const TKey &  key,
UValue &&  val,
std::chrono::milliseconds  duration 
)
inline

Definition at line 92 of file Cache.h.

◆ Put() [2/2]

template<typename TKey , typename TValue >
template<typename UValue >
void Aws::Utils::Cache< TKey, TValue >::Put ( TKey &&  key,
UValue &&  val,
std::chrono::milliseconds  duration 
)
inline

Add or update a cache entry. When the number of items in the cache reaches the maximum, newly added items will evict expired items. If the cache size is at its maximum and none of the existing items are expired, the entry that is closest to expiration will be evicted.

Note: Expired entries are not evicted upon expiration, but rather when space is needed for new items.

Parameters
keyThe of key of the entry that will be used to retrieve it.
valThe value of the entry to associate with the given key.
durationThe duration after which the cache entry will expire and become a candidate for eviction.

Definition at line 72 of file Cache.h.

◆ Transform()

template<typename TKey , typename TValue >
void Aws::Utils::Cache< TKey, TValue >::Transform ( TransformFunction  function)
inline

Definition at line 118 of file Cache.h.


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