#include <Cache.h>
Public Member Functions | |
Constructors | |
| Cache ()=default | |
| Cache (const std::initializer_list< std::pair< KeyType, std::function< boost::any() > > > &initList) | |
Modification | |
| template<typename T > | |
| void | add (const KeyType &key, const T &value) |
| Adds a data value for a key value into the cache. | |
| template<typename T > | |
| T | getGeneratable (const KeyType &key) |
| template<typename T > | |
| void | changeGeneratable (const KeyType &key, std::function< > modifyingUnaryFunction) |
| Permits the modification of a generatable cache item via a raw pointer. | |
| void | invalidate () |
| Invalidates the entire cache, removing all stored data. | |
| void | invalidate (const KeyType &key) |
| Selectively invalidates cache entries. | |
Information | |
| template<typename T > | |
| boost::optional< T > | getOption (const KeyType &key) const |
| Fetches a cache entry via an optional. | |
| bool | has (const KeyType &key) const |
| Tests whether the cache contains an entry for a key. | |
Private Attributes | |
| std::map< KeyType, boost::any > | cache_ |
| Cache data. | |
|
std::map< KeyType, std::function< boost::any()> > | generationMap_ |
| Map of key values to generating functions. | |
A class that can store completely variant types in a type safe manner using boost::any. Only the key type is fixed. Selective invalidation of cached data is possible, and cache elements can also be set as generatable, i.e. a function that generates the cache data can be passed. On first use, the cache element is then generated.
|
inline |
Fetches the value of a generatable cache item. Handles all corner cases of whether the cache element is present or not.