MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
Public 成员函数 | Private 属性 | 所有成员列表
oceanbase::ObLRUCache< KeyType, ValueType > 模板类 参考

A thread-safe implementation of an LRU (Least Recently Used) cache. 更多...

#include <ob_lru_cache.h>

Public 成员函数

 ObLRUCache (size_t capacity)
 Constructs an ObLRUCache with a specified capacity. 更多...
 
bool get (const KeyType &key, ValueType &value)
 Retrieves a value from the cache using the specified key. 更多...
 
void put (const KeyType &key, const ValueType &value)
 Inserts a key-value pair into the cache. 更多...
 
bool contains (const KeyType &key) const
 Checks whether the specified key exists in the cache. 更多...
 

Private 属性

size_t capacity_
 The maximum number of elements the cache can hold.
 

详细描述

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.

模板参数
KeyTypeThe type of keys used to identify cache entries.
ValueTypeThe type of values stored in the cache.

构造及析构函数说明

◆ ObLRUCache()

template<typename KeyType , typename ValueType >
oceanbase::ObLRUCache< KeyType, ValueType >::ObLRUCache ( size_t  capacity)
inline

Constructs an ObLRUCache with a specified capacity.

参数
capacityThe maximum number of elements the cache can hold.

成员函数说明

◆ contains()

template<typename KeyType , typename ValueType >
bool oceanbase::ObLRUCache< KeyType, ValueType >::contains ( const KeyType &  key) const
inline

Checks whether the specified key exists in the cache.

参数
keyThe key to check in the cache.
返回
true if the key exists; false otherwise.

◆ get()

template<typename KeyType , typename ValueType >
bool oceanbase::ObLRUCache< KeyType, ValueType >::get ( const KeyType &  key,
ValueType &  value 
)
inline

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).

参数
keyThe key to search for in the cache.
valueA reference to store the value associated with the key.
返回
true if the key is found and the value is retrieved; false otherwise.

◆ put()

template<typename KeyType , typename ValueType >
void oceanbase::ObLRUCache< KeyType, ValueType >::put ( const KeyType &  key,
const ValueType &  value 
)
inline

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.

参数
keyThe key to insert into the cache.
valueThe value to associate with the specified key.

该类的文档由以下文件生成: