|
| CacheMap () |
| Construct a CacheMap without default fetch function. More...
|
|
| CacheMap (FetchFn fetchFn) |
| Construct a CacheMap with default fetch function. More...
|
|
void | setFetchFn (FetchFn fetchFn, bool clear=false) |
| Set the fetch function, optionally clearing the cache (disabled by default). More...
|
|
ValueT & | get (const KeyT &key, std::function< ValueT(KeyT)> fetchFn) |
| Get a value for the given key, using the given fetch function. More...
|
|
ValueT & | get (const KeyT &key) |
| Get a value for the given key, using the stored fetch function. Make sure to pass set a fetch function via the constructor or setFetchFn() . More...
|
|
ValueT & | get (const KeyT &key) const |
| Get a value for the given key (const version). More...
|
|
ValueT & | insert (const KeyT &key) |
| Explicitly insert a value using the stored fetch function. More...
|
|
ValueT & | insert (const KeyT &key, const ValueT &value) |
| Explicitly insert a value. More...
|
|
ValueT & | insert (const KeyT &key, std::function< ValueT(KeyT)> fetchFn) |
| Explicitly insert a value using the fetch function. More...
|
|
void | clear () |
|
size_t | size () const |
|
bool | empty () const |
|
bool | contains (const KeyT &key) const |
|
auto | begin () |
|
auto | begin () const |
|
auto | end () |
|
auto | end () const |
|
auto | find (const KeyT &key) |
|
auto | find (const KeyT &key) const |
|
template<class KeyT, class ValueT, template< class ... > class MapT = std::map>
class simox::caching::CacheMap< KeyT, ValueT, MapT >
Wrapper for using a std::map
or std::unordered_map
as a data cache.
A CacheMap
uses a "fetch function" (FetchFn
) to retrieve values for keys that are not in the cache. It can be specified (among others) in the constructor, via setFetchFn()
or when accessing an item via get()
.
template<class KeyT , class ValueT , template< class ... > class MapT = std::map>
Get a value for the given key (const version).
This does not change the cache, therefore accessing a non-existing key will cause an exception.
- Parameters
-
- Returns
- The stored value if it exists.
- Exceptions
-
<tt>simox::error::SimoxError</tt> | If the key is not known. |