|
Doxygen
|
#include <src/cache.h>
Public Types | |
| using | kv_pair = std::pair<K,V> |
| using | iterator = typename std::list<kv_pair>::iterator |
| using | const_iterator = typename std::list<kv_pair>::const_iterator |
Public Member Functions | |
| Cache (size_t capacity) | |
| creates a cache that can hold capacity elements | |
| V * | insert (const K &key, V &&value) |
| Inserts value under key in the cache. | |
| V * | insert (const K &key, const V &value) |
| Inserts value under key in the cache. | |
| void | remove (const K &key) |
| V * | find (const K &key) |
| size_t | size () const |
| Returns the number of values stored in the cache. | |
| size_t | capacity () const |
| Returns the maximum number of values that can be stored in the cache. | |
| uint64_t | hits () const |
| Returns how many of the find() calls did find a value in the cache. | |
| uint64_t | misses () const |
| Returns how many of the find() calls did not found a value in the cache. | |
| void | clear () |
| Clears all values in the cache. | |
| iterator | begin () |
| iterator | end () |
| const_iterator | begin () const |
| const_iterator | end () const |
Private Member Functions | |
| void | resize () |
Private Attributes | |
| size_t | m_capacity |
| std::list< kv_pair > | m_cacheItemList |
| std::unordered_map< K, iterator > | m_cacheItemMap |
| uint64_t | m_hits =0 |
| uint64_t | m_misses =0 |
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).
| using Cache< K, V >::kv_pair = std::pair<K,V> |
|
inline |
creates a cache that can hold capacity elements
Definition at line 39 of file cache.h.
References capacity(), and m_capacity.
|
inline |
|
inline |
Returns the maximum number of values that can be stored in the cache.
Definition at line 132 of file cache.h.
References m_capacity.
Referenced by Cache().
|
inline |
Clears all values in the cache.
Definition at line 150 of file cache.h.
References m_cacheItemList, and m_cacheItemMap.
|
inline |
|
inline |
Finds a value in the cache given the corresponding key.
Definition at line 105 of file cache.h.
References m_cacheItemList, m_cacheItemMap, m_hits, and m_misses.
|
inline |
|
inline |
Inserts value under key in the cache.
Definition at line 67 of file cache.h.
References m_cacheItemList, m_cacheItemMap, and resize().
|
inline |
Inserts value under key in the cache.
Definition at line 44 of file cache.h.
References m_cacheItemList, m_cacheItemMap, and resize().
|
inline |
|
inline |
Removes entry key from the cache.
Definition at line 91 of file cache.h.
References m_cacheItemList, and m_cacheItemMap.
|
inlineprivate |
Definition at line 163 of file cache.h.
References m_cacheItemList, m_cacheItemMap, and m_capacity.
|
inline |
Returns the number of values stored in the cache.
Definition at line 126 of file cache.h.
References m_cacheItemMap.
|
private |
Definition at line 174 of file cache.h.
Referenced by Cache(), capacity(), and resize().
|
private |
|
private |