The Cache
Class Template Reference
Declaration
Included Headers
Public Member Typedefs Index
template <typename K, typename V> | |
using | kv_pair = std::pair< K, V > |
template <typename K, typename V> | |
using | iterator = typename std::list< kv_pair >::iterator |
template <typename K, typename V> | |
using | const_iterator = typename std::list< kv_pair >::const_iterator |
Public Constructors Index
template <typename K, typename V> | |
Cache (size_t capacity) | |
creates a cache that can hold capacity elements More... | |
Public Member Functions Index
template <typename K, typename V> | |
V * | insert (const K &key, V &&value) |
Inserts value under key in the cache. More... | |
template <typename K, typename V> | |
V * | insert (const K &key, const V &value) |
Inserts value under key in the cache. More... | |
template <typename K, typename V> | |
void | remove (const K &key) |
template <typename K, typename V> | |
V * | find (const K &key) |
template <typename K, typename V> | |
size_t | size () const |
Returns the number of values stored in the cache. More... | |
template <typename K, typename V> | |
size_t | capacity () const |
Returns the maximum number of values that can be stored in the cache. More... | |
template <typename K, typename V> | |
uint64_t | hits () const |
Returns how many of the find() calls did find a value in the cache. More... | |
template <typename K, typename V> | |
uint64_t | misses () const |
Returns how many of the find() calls did not found a value in the cache. More... | |
template <typename K, typename V> | |
void | clear () |
Clears all values in the cache. More... | |
template <typename K, typename V> | |
iterator | begin () |
template <typename K, typename V> | |
iterator | end () |
template <typename K, typename V> | |
const_iterator | begin () const |
template <typename K, typename V> | |
const_iterator | end () const |
Private Member Functions Index
template <typename K, typename V> | |
void | resize () |
Private Member Attributes Index
template <typename K, typename V> | |
size_t | m_capacity |
template <typename K, typename V> | |
std::list< kv_pair > | m_cacheItemList |
template <typename K, typename V> | |
std::unordered_map< K, iterator > | m_cacheItemMap |
template <typename K, typename V> | |
uint64_t | m_hits =0 |
template <typename K, typename V> | |
uint64_t | m_misses =0 |
Description
Fixed size cache for value type V using keys of type K.
When the maximum capacity has reached, the least recently used value is removed from the cache (LRU strategy).
Definition at line 31 of file cache.h.
Public Member Typedefs
const_iterator
|
Definition at line 36 of file cache.h.
iterator
|
kv_pair
Public Constructors
Cache()
| inline |
creates a cache that can hold capacity elements
Definition at line 39 of file cache.h.
References Cache< K, V >::capacity and Cache< K, V >::m_capacity.
Public Member Functions
begin()
| inline |
Definition at line 156 of file cache.h.
Reference Cache< K, V >::m_cacheItemList.
begin()
| inline |
Definition at line 158 of file cache.h.
Reference Cache< K, V >::m_cacheItemList.
capacity()
| inline |
Returns the maximum number of values that can be stored in the cache.
Definition at line 132 of file cache.h.
Reference Cache< K, V >::m_capacity.
Referenced by Cache< K, V >::Cache.
clear()
| inline |
Clears all values in the cache.
Definition at line 150 of file cache.h.
References Cache< K, V >::m_cacheItemList and Cache< K, V >::m_cacheItemMap.
end()
| inline |
Definition at line 157 of file cache.h.
Reference Cache< K, V >::m_cacheItemList.
end()
| inline |
Definition at line 159 of file cache.h.
Reference Cache< K, V >::m_cacheItemList.
find()
| inline |
Finds a value in the cache given the corresponding key.
- Returns
a pointer to the value or nullptr if the key is not found in the cache
Definition at line 105 of file cache.h.
References Cache< K, V >::m_cacheItemList, Cache< K, V >::m_cacheItemMap, Cache< K, V >::m_hits and Cache< K, V >::m_misses.
hits()
| inline |
insert()
| inline |
Inserts value under key in the cache.
Definition at line 44 of file cache.h.
References Cache< K, V >::m_cacheItemList, Cache< K, V >::m_cacheItemMap and Cache< K, V >::resize.
insert()
| inline |
Inserts value under key in the cache.
Definition at line 67 of file cache.h.
References Cache< K, V >::m_cacheItemList, Cache< K, V >::m_cacheItemMap and Cache< K, V >::resize.
misses()
| inline |
remove()
| inline |
Removes entry key from the cache.
this invalidates any iterators
Definition at line 91 of file cache.h.
References Cache< K, V >::m_cacheItemList and Cache< K, V >::m_cacheItemMap.
size()
| inline |
Returns the number of values stored in the cache.
Definition at line 126 of file cache.h.
Reference Cache< K, V >::m_cacheItemMap.
Private Member Functions
resize()
| inline |
Definition at line 163 of file cache.h.
References Cache< K, V >::m_cacheItemList, Cache< K, V >::m_cacheItemMap and Cache< K, V >::m_capacity.
Referenced by Cache< K, V >::insert and Cache< K, V >::insert.
Private Member Attributes
m_cacheItemList
|
Definition at line 176 of file cache.h.
Referenced by Cache< K, V >::begin, Cache< K, V >::begin, Cache< K, V >::clear, Cache< K, V >::end, Cache< K, V >::end, Cache< K, V >::find, Cache< K, V >::insert, Cache< K, V >::insert, Cache< K, V >::remove and Cache< K, V >::resize.
m_cacheItemMap
|
Definition at line 178 of file cache.h.
Referenced by Cache< K, V >::clear, Cache< K, V >::find, Cache< K, V >::insert, Cache< K, V >::insert, Cache< K, V >::remove, Cache< K, V >::resize and Cache< K, V >::size.
m_capacity
|
Definition at line 174 of file cache.h.
Referenced by Cache< K, V >::Cache, Cache< K, V >::capacity and Cache< K, V >::resize.
m_hits
|
Definition at line 179 of file cache.h.
Referenced by Cache< K, V >::find and Cache< K, V >::hits.
m_misses
|
Definition at line 180 of file cache.h.
Referenced by Cache< K, V >::find and Cache< K, V >::misses.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus by Doxygen 1.14.0.