OpenTTD Source 20250521-master-g82876c25e0
|
Size limited cache with a least recently used eviction strategy. More...
#include <lrucache.hpp>
Public Member Functions | |
LRUCache (size_t max_items) | |
Construct new LRU cache map. | |
bool | Contains (const Tkey &key) |
Test if a key is already contained in the cache. | |
void | Insert (const Tkey &key, Tdata &&item) |
Insert a new data item with a specified key. | |
void | Clear () |
Clear the cache. | |
const Tdata & | Get (const Tkey &key) |
Get an item from the cache. | |
Tdata * | GetIfValid (const auto &key) |
Get an item from the cache. | |
Private Types | |
using | PairType = std::pair< Tkey, Tdata > |
using | StorageType = std::list< PairType > |
using | IteratorType = StorageType::iterator |
using | LookupType = std::unordered_map< Tkey, IteratorType, Thash, Tequality > |
Private Attributes | |
StorageType | data |
Ordered list of all items. | |
LookupType | lookup |
Map of keys to items. | |
const size_t | capacity |
Number of items to cache. | |
Size limited cache with a least recently used eviction strategy.
Tkey | Type of the cache key. |
Tdata | Type of the cache item. |
Definition at line 23 of file lrucache.hpp.
|
private |
Definition at line 27 of file lrucache.hpp.
|
private |
Definition at line 28 of file lrucache.hpp.
|
private |
Definition at line 25 of file lrucache.hpp.
|
private |
Definition at line 26 of file lrucache.hpp.
|
inline |
Construct new LRU cache map.
max_items | Number of items to store at most. |
Definition at line 40 of file lrucache.hpp.
|
inline |
Clear the cache.
Definition at line 80 of file lrucache.hpp.
Referenced by OpenGLBackend::InternalClearCursorCache().
|
inline |
Test if a key is already contained in the cache.
key | The key to search. |
Definition at line 47 of file lrucache.hpp.
Referenced by OpenGLBackend::DrawMouseCursor().
|
inline |
Get an item from the cache.
key | The key to look up. |
Definition at line 92 of file lrucache.hpp.
Referenced by OpenGLBackend::DrawMouseCursor().
|
inline |
Get an item from the cache.
key | The key to look up. |
Definition at line 108 of file lrucache.hpp.
|
inline |
Insert a new data item with a specified key.
key | Key under which the item should be stored. |
item | Item to insert. |
Definition at line 57 of file lrucache.hpp.
References LRUCache< Tkey, Tdata, Thash, Tequality >::data.
Referenced by OpenGLBackend::Encode().
|
private |
Number of items to cache.
Definition at line 33 of file lrucache.hpp.
|
private |
Ordered list of all items.
Definition at line 30 of file lrucache.hpp.
Referenced by LRUCache< Tkey, Tdata, Thash, Tequality >::Insert().
|
private |
Map of keys to items.
Definition at line 31 of file lrucache.hpp.