A basic LRU (least recently used) cache implementation. Also supports a custom callback for when an item is removed.
More...
#include <LRUCache.hpp>
|
typedef std::pair< Key, Value > | KeyValuePair |
|
typedef std::list< KeyValuePair >::iterator | ListIterator |
|
|
| LRUCache () |
| Default constructor initializes a cache of size 100 and no callback.
|
|
| LRUCache (const unsigned int size, const std::function< void(const Key &, const Value &)> &func=nullptr) |
| Create a LRU Cache with the given size. More...
|
|
void | addData (const Key &key, const Value &data) |
| Add data to the cache using the given key. More...
|
|
Value | getData (const Key &key) |
| Returns the cached value associated with the given key. More...
|
|
bool | hasKey (const Key &key) |
| Returns if the given key has a cached value. More...
|
|
unsigned int | size () |
| Returns the number of items in the cache. More...
|
|
| ~LRUCache () |
| Calls callback function on each stored item when deleted.
|
|
template<typename Key, typename Value>
class Aether::LRUCache< Key, Value >
A basic LRU (least recently used) cache implementation. Also supports a custom callback for when an item is removed.
◆ LRUCache()
template<typename Key, typename Value>
Aether::LRUCache< Key, Value >::LRUCache |
( |
const unsigned int |
size, |
|
|
const std::function< void(const Key &, const Value &)> & |
func = nullptr |
|
) |
| |
|
inline |
Create a LRU Cache with the given size.
- Parameters
-
size | Maximum number of elements to cache. |
func | Callback to invoke when an element is removed (optional) |
◆ addData()
template<typename Key, typename Value>
void Aether::LRUCache< Key, Value >::addData |
( |
const Key & |
key, |
|
|
const Value & |
data |
|
) |
| |
|
inline |
Add data to the cache using the given key.
- Parameters
-
key | Key to use for looking up the data. |
data | Data associated with key. |
◆ getData()
template<typename Key, typename Value>
Returns the cached value associated with the given key.
- Note
- The returned value is undefined if the key is not cached, please use hasKey() first to check that it is in the cache!
- Parameters
-
key | Key to search for matching value with |
- Returns
- Value/data associated with key
◆ hasKey()
template<typename Key, typename Value>
Returns if the given key has a cached value.
- Parameters
-
- Returns
- true if key has cached value, false otherwise.
◆ size()
template<typename Key, typename Value>
Returns the number of items in the cache.
- Returns
- Number of items in cache.
The documentation for this class was generated from the following file: