template<typename KeyType, typename ValueType>
class oceanbase::ObLRUCache< KeyType, ValueType >
A thread-safe implementation of an LRU (Least Recently Used) cache.
The ObLRUCache
class provides a fixed-size cache that evicts the least recently used entries when the cache exceeds its capacity. It supports thread-safe operations for inserting, retrieving, and checking the existence of cache entries.
- 模板参数
-
KeyType | The type of keys used to identify cache entries. |
ValueType | The type of values stored in the cache. |
template<typename KeyType , typename ValueType >
Retrieves a value from the cache using the specified key.
This method searches for the specified key in the cache. If the key is found, the corresponding value is returned and the key-value pair is moved to the front of the LRU list (indicating recent use).
- 参数
-
key | The key to search for in the cache. |
value | A reference to store the value associated with the key. |
- 返回
true
if the key is found and the value is retrieved; false
otherwise.
template<typename KeyType , typename ValueType >
Inserts a key-value pair into the cache.
If the key already exists in the cache, its value is updated, and the key-value pair is moved to the front of the LRU list. If the cache exceeds its capacity after insertion, the least recently used entry is evicted.
- 参数
-
key | The key to insert into the cache. |
value | The value to associate with the specified key. |