|
| Cache (Policy policy) |
| Construct a new Cache object. More...
|
|
void | reserve (std::size_t size) |
| Reserve space for the cache to avoid unnecessary reallocations. More...
|
|
std::size_t | size () const |
| Returns the number of elements in the cache. More...
|
|
std::size_t | max_size () const |
| Returns the maximum number of elements the cache can ever hold. More...
|
|
bool | empty () const |
| Returns whether the cache is empty. More...
|
|
void | clear () |
| Removes all elements from the cache. More...
|
|
template<typename KArg , typename VArg > |
bool | insert (KArg &&key, VArg &&value) |
| Inserts a key-value pair into the cache. More...
|
|
bool | contains (const K &key) const |
| Check if the cache contains a key. More...
|
|
iterator | begin () |
| Returns an iterator to the first element in the cache. More...
|
|
iterator | end () |
| Returns an iterator to the element following the last element in the cache. More...
|
|
iterator | cbegin () const |
| Returns a const iterator to the first element in the cache. More...
|
|
iterator | cend () const |
| Returns a const iterator to the element following the last element in the cache. More...
|
|
iterator | find (const K &key) |
| Returns an iterator to the element with the given key. More...
|
|
V & | at (const K &key) |
| Returns a reference to the value associated with the given key. More...
|
|
const V & | at (const K &key) const |
| Returns a const reference to the value associated with the given key. More...
|
|
K & | front () |
| Returns the reference the first element in the cache. More...
|
|
K & | back () |
| Returns the reference the last element in the cache. More...
|
|
const K & | front () const |
| Returns const reference the first element in the cache. More...
|
|
const K & | back () const |
| Returns const reference the last element in the cache. More...
|
|
template<typename K, typename V, template< typename, typename > class CachePolicy>
class boxes::cache::Cache< K, V, CachePolicy >
Generic cache with pluggable eviction policies.
- Template Parameters
-
K | key type (must be hashable, comparable and copyable) |
V | value type |
CachePolicy | eviction policy to use |
Definition at line 337 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns a reference to the value associated with the given key.
The key, if present, is refreshed in accordance with the eviction policy.
If the key is not in the cache, an exception is thrown.
- Parameters
-
- Returns
- reference to the value associated with the given key
Definition at line 548 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns the reference the last element in the cache.
The order of elements in the cache is defined by the eviction policy. Refer to the specific eviction policy for details.
- Returns
- reference to the key of the last element in the cache
Definition at line 583 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns an iterator to the first element in the cache.
The iteration order is defined by the eviction policy.
- Returns
- iterator to the first element in the cache
Definition at line 493 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns an iterator to the element following the last element in the cache.
The iteration order is defined by the eviction policy.
- Returns
- iterator to the element following the last element in the cache
Definition at line 503 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns an iterator to the element with the given key.
The key, if present, is refreshed in accordance with the eviction policy.
- Parameters
-
- Returns
- iterator to the element with the given key, or end() if the key is not in the cache
Definition at line 530 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns the reference the first element in the cache.
The order of elements in the cache is defined by the eviction policy. Refer to the specific eviction policy for details.
- Returns
- reference to the first element in the cache
Definition at line 573 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
template<typename KArg , typename VArg >
Inserts a key-value pair into the cache.
If the key is already in the cache, the value is updated and the key is refreshed in accordance with the eviction policy.
- Parameters
-
key | key to insert |
value | value to insert |
- Returns
- true if the key was inserted, false if the key was already in the cache
Definition at line 458 of file cache.hpp.
template<typename K , typename V , template< typename, typename > class CachePolicy>
Returns the maximum number of elements the cache can ever hold.
This is the upper water mark for the cache as constrained by platform implementation.
This number is not synonymous with the cache size, as restricted by the eviction policy.
- Returns
- maximum number of elements the cache can ever hold
Definition at line 429 of file cache.hpp.