LibreOffice Module stoc (master) 1
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
LRU_Cache< t_Key, t_Val, t_KeyHash > Class Template Reference

Implementation of a least recently used (lru) cache. More...

#include <lrucache.hxx>

Inheritance diagram for LRU_Cache< t_Key, t_Val, t_KeyHash >:
[legend]
Collaboration diagram for LRU_Cache< t_Key, t_Val, t_KeyHash >:
[legend]

Classes

struct  CacheEntry
 

Public Member Functions

 LRU_Cache ()
 Constructor:
More...
 
t_Val getValue (const t_Key &rKey) const
 Retrieves a value from the cache. More...
 
void setValue (const t_Key &rKey, const t_Val &rValue)
 Sets a value to be cached for given key. More...
 
void clear ()
 Clears the cache, thus releasing all cached elements and keys. More...
 

Private Types

typedef std::unordered_map< t_Key, CacheEntry *, t_KeyHash > t_Key2Element
 

Private Member Functions

void toFront (CacheEntry *pEntry) const
 

Private Attributes

std::mutex _aCacheMutex
 
sal_Int32 _nCachedElements
 
t_Key2Element _aKey2Element
 
std::unique_ptr< CacheEntry[]> _pBlock
 
CacheEntry_pHead
 
CacheEntry_pTail
 

Detailed Description

template<class t_Key, class t_Val, class t_KeyHash>
class LRU_Cache< t_Key, t_Val, t_KeyHash >

Implementation of a least recently used (lru) cache.


Definition at line 37 of file lrucache.hxx.

Member Typedef Documentation

◆ t_Key2Element

template<class t_Key , class t_Val , class t_KeyHash >
typedef std::unordered_map< t_Key, CacheEntry *, t_KeyHash > LRU_Cache< t_Key, t_Val, t_KeyHash >::t_Key2Element
private

Definition at line 46 of file lrucache.hxx.

Constructor & Destructor Documentation

◆ LRU_Cache()

template<class t_Key , class t_Val , class t_KeyHash >
LRU_Cache< t_Key, t_Val, t_KeyHash >::LRU_Cache
inlineexplicit

Constructor:

Parameters
nCachedElementsnumber of elements to be cached; default param set to 128

Definition at line 84 of file lrucache.hxx.

References nPos, and LRU_Cache< t_Key, t_Val, t_KeyHash >::CacheEntry::pPred.

Member Function Documentation

◆ clear()

template<class t_Key , class t_Val , class t_KeyHash >
void LRU_Cache< t_Key, t_Val, t_KeyHash >::clear
inline

Clears the cache, thus releasing all cached elements and keys.


Definition at line 185 of file lrucache.hxx.

References nPos, and SAL_INFO.

Referenced by stoc_corefl::IdlReflectionServiceImpl::disposing().

◆ getValue()

template<class t_Key , class t_Val , class t_KeyHash >
t_Val LRU_Cache< t_Key, t_Val, t_KeyHash >::getValue ( const t_Key &  rKey) const
inline

Retrieves a value from the cache.

Returns default constructed value, if none was found.

Parameters
rKeya key
Returns
value

Definition at line 127 of file lrucache.hxx.

References LRU_Cache< t_Key, t_Val, t_KeyHash >::CacheEntry::aKey, LRU_Cache< t_Key, t_Val, t_KeyHash >::CacheEntry::aVal, and SAL_INFO.

Referenced by stoc_corefl::IdlReflectionServiceImpl::forName(), stoc_corefl::IdlReflectionServiceImpl::forType(), and stoc_corefl::IdlReflectionServiceImpl::getByHierarchicalName().

◆ setValue()

template<class t_Key , class t_Val , class t_KeyHash >
void LRU_Cache< t_Key, t_Val, t_KeyHash >::setValue ( const t_Key &  rKey,
const t_Val &  rValue 
)
inline

◆ toFront()

template<class t_Key , class t_Val , class t_KeyHash >
void LRU_Cache< t_Key, t_Val, t_KeyHash >::toFront ( CacheEntry pEntry) const
inlineprivate

Member Data Documentation

◆ _aCacheMutex

template<class t_Key , class t_Val , class t_KeyHash >
std::mutex LRU_Cache< t_Key, t_Val, t_KeyHash >::_aCacheMutex
mutableprivate

Definition at line 48 of file lrucache.hxx.

◆ _aKey2Element

template<class t_Key , class t_Val , class t_KeyHash >
t_Key2Element LRU_Cache< t_Key, t_Val, t_KeyHash >::_aKey2Element
private

Definition at line 50 of file lrucache.hxx.

◆ _nCachedElements

template<class t_Key , class t_Val , class t_KeyHash >
sal_Int32 LRU_Cache< t_Key, t_Val, t_KeyHash >::_nCachedElements
private

Definition at line 49 of file lrucache.hxx.

◆ _pBlock

template<class t_Key , class t_Val , class t_KeyHash >
std::unique_ptr<CacheEntry[]> LRU_Cache< t_Key, t_Val, t_KeyHash >::_pBlock
private

Definition at line 52 of file lrucache.hxx.

◆ _pHead

template<class t_Key , class t_Val , class t_KeyHash >
CacheEntry* LRU_Cache< t_Key, t_Val, t_KeyHash >::_pHead
mutableprivate

Definition at line 53 of file lrucache.hxx.

◆ _pTail

template<class t_Key , class t_Val , class t_KeyHash >
CacheEntry* LRU_Cache< t_Key, t_Val, t_KeyHash >::_pTail
mutableprivate

Definition at line 54 of file lrucache.hxx.


The documentation for this class was generated from the following file: