Size limited cache with a least recently used eviction strategy.
More...
#include <lrucache.hpp>
|
| | LRUCache (size_t max_items) |
| | Construct new LRU cache map. More...
|
| |
| bool | Contains (const Tkey key) |
| | Test if a key is already contained in the cache. More...
|
| |
| Tdata * | Insert (const Tkey key, Tdata *item) |
| | Insert a new data item with a specified key. More...
|
| |
| Tdata * | Pop () |
| | Pop the least recently used item. More...
|
| |
| Tdata * | Get (const Tkey key) |
| | Get an item from the cache. More...
|
| |
|
|
typedef std::pair< Tkey, Tdata * > | Tpair |
| |
|
typedef std::list< Tpair >::iterator | Titer |
| |
|
|
std::list< Tpair > | data |
| | Ordered list of all items.
|
| |
|
std::unordered_map< Tkey, Titer > | lookup |
| | Map of keys to items.
|
| |
|
const size_t | capacity |
| | Number of items to cache.
|
| |
template<class Tkey, class Tdata>
class LRUCache< Tkey, Tdata >
Size limited cache with a least recently used eviction strategy.
- Template Parameters
-
| Tkey | Type of the cache key. |
| Tdata | Type of the cache item. The cache will store a pointer of this type. |
Definition at line 27 of file lrucache.hpp.
◆ LRUCache()
template<class Tkey , class Tdata >
Construct new LRU cache map.
- Parameters
-
| max_items | Number of items to store at most. |
Definition at line 42 of file lrucache.hpp.
◆ Contains()
template<class Tkey , class Tdata >
| bool LRUCache< Tkey, Tdata >::Contains |
( |
const Tkey |
key | ) |
|
|
inline |
◆ Get()
template<class Tkey , class Tdata >
| Tdata* LRUCache< Tkey, Tdata >::Get |
( |
const Tkey |
key | ) |
|
|
inline |
Get an item from the cache.
- Parameters
-
- Returns
- The item value.
- Note
- Throws if item not found.
Definition at line 106 of file lrucache.hpp.
◆ Insert()
template<class Tkey , class Tdata >
| Tdata* LRUCache< Tkey, Tdata >::Insert |
( |
const Tkey |
key, |
|
|
Tdata * |
item |
|
) |
| |
|
inline |
Insert a new data item with a specified key.
- Parameters
-
| key | Key under which the item should be stored. |
| item | Item to insert. |
- Returns
- Evicted item or nullptr, if no item had to be evicted.
Definition at line 60 of file lrucache.hpp.
◆ Pop()
template<class Tkey , class Tdata >
Pop the least recently used item.
- Returns
- The item value or nullptr if no items cached.
Definition at line 90 of file lrucache.hpp.
The documentation for this class was generated from the following file: