ddc
Public Types | Public Member Functions | Public Attributes | List of all members
ddcLRUCache< Key, Val > Class Template Reference

generic least-recently-used cache template More...

#include <LRUCache.h>

Inheritance diagram for ddcLRUCache< Key, Val >:
Inheritance graph
[legend]

Public Types

typedef Key KeyT
 key type More...
 
typedef Val ValT
 value type More...
 
typedef pthread_mutex_t * MutexT
 mutex type (pthreads enabled) More...
 
typedef std::pair< KeyT, ValTItemT
 elementary data item: (key,val) pair More...
 
typedef std::list< ItemTListT
 list of (key,val) pairs, position indicates recency of use (most recent first) More...
 
typedef std::map< KeyT, typename ListT::iterator > MapT
 maps keys to lru-list iterators, used to check key existence More...
 
typedef MapT::iterator iterator
 iterator wraps MapT::iterator (~ pair< KeyT, pair<KeyT,ValT>* > *) More...
 
typedef MapT::const_iterator const_iterator
 const_iterator wraps MapT::const_iterator More...
 

Public Member Functions

 ddcLRUCache (size_t capacity=1024, MutexT mutex=NULL)
 default constructor More...
 
void clear ()
 clear all cached items (no implicit locks) More...
 
void clean ()
 drop least recently used cache items until size <= capacity More...
 
MutexT mutex () const
 get mutex pointer More...
 
MutexT mutex (MutexT mut)
 set mutex pointer More...
 
size_t size () const
 get number of currently cached items More...
 
size_t capacity () const
 get cache capacity More...
 
size_t reserve (size_t cap)
 update cache capacity; implicitly calls clean() More...
 
void lock ()
 lock the cache mutex, if any More...
 
void unlock ()
 unlock cache mutex More...
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
iterator find (const KeyT &key)
 find cached item; returns end() if not found, does NOT update the MRU-list (non-const) More...
 
iterator lower_bound (const KeyT &key)
 find lower bound for cache key; does NOT update the MRU-list (non-const) More...
 
iterator upper_bound (const KeyT &key)
 find upper bound for cache key; does NOT update the MRU-list (non-const) More...
 
const_iterator find (const KeyT &key) const
 find cached item; returns end() if not found; does NOT update the MRU-list (const version) More...
 
const_iterator lower_bound (const KeyT &key) const
 find lower bound for cache key; does NOT update the MRU-list (const version) More...
 
const_iterator upper_bound (const KeyT &key) const
 find upper bound for cache key; does NOT update the MRU-list (const version) More...
 
iterator get (const KeyT &key)
 get cached item, promoting it to MRU position if already exists; return end() if key is not found More...
 
void promote (const_iterator &it)
 promote an existing item to the most-recently-used position More...
 
void promote (iterator &it)
 promote an existing item to the most-recently-used position More...
 
void insert (const KeyT &key, const ValT &val)
 

Public Attributes

size_t m_capacity
 maximum number of cached items More...
 
size_t m_size
 current number of cached items More...
 
ListT m_list
 list of (key,val) pairs, position indicates recency of use (most recent first) More...
 
MapT m_map
 maps keys to m_list iterators, used to check key existence More...
 
MutexT m_mutex
 mutex pointer to use for lock() and unlock() methods More...
 

Detailed Description

template<class Key, class Val>
class ddcLRUCache< Key, Val >

generic least-recently-used cache template

Member Typedef Documentation

◆ KeyT

template<class Key, class Val>
typedef Key ddcLRUCache< Key, Val >::KeyT

key type

◆ ValT

template<class Key, class Val>
typedef Val ddcLRUCache< Key, Val >::ValT

value type

◆ MutexT

template<class Key, class Val>
typedef pthread_mutex_t* ddcLRUCache< Key, Val >::MutexT

mutex type (pthreads enabled)

◆ ItemT

template<class Key, class Val>
typedef std::pair<KeyT,ValT> ddcLRUCache< Key, Val >::ItemT

elementary data item: (key,val) pair

◆ ListT

template<class Key, class Val>
typedef std::list<ItemT> ddcLRUCache< Key, Val >::ListT

list of (key,val) pairs, position indicates recency of use (most recent first)

◆ MapT

template<class Key, class Val>
typedef std::map<KeyT, typename ListT::iterator> ddcLRUCache< Key, Val >::MapT

maps keys to lru-list iterators, used to check key existence

◆ iterator

template<class Key, class Val>
typedef MapT::iterator ddcLRUCache< Key, Val >::iterator

iterator wraps MapT::iterator (~ pair< KeyT, pair<KeyT,ValT>* > *)

◆ const_iterator

template<class Key, class Val>
typedef MapT::const_iterator ddcLRUCache< Key, Val >::const_iterator

const_iterator wraps MapT::const_iterator

Constructor & Destructor Documentation

◆ ddcLRUCache()

template<class Key, class Val>
ddcLRUCache< Key, Val >::ddcLRUCache ( size_t  capacity = 1024,
MutexT  mutex = NULL 
)
inline

default constructor

Member Function Documentation

◆ clear()

template<class Key, class Val>
void ddcLRUCache< Key, Val >::clear ( void  )
inline

clear all cached items (no implicit locks)

Referenced by NavHintCache::clear(), CDDCLeafServer::handle__clear_cache(), and CDDCBranchServer::handle__clear_cache().

Here is the caller graph for this function:

◆ clean()

template<class Key, class Val>
void ddcLRUCache< Key, Val >::clean ( )
inline

drop least recently used cache items until size <= capacity

Referenced by ddcLRUCache< KeyT, ValT >::insert(), and ddcLRUCache< KeyT, ValT >::reserve().

Here is the caller graph for this function:

◆ mutex() [1/2]

template<class Key, class Val>
MutexT ddcLRUCache< Key, Val >::mutex ( ) const
inline

get mutex pointer

◆ mutex() [2/2]

template<class Key, class Val>
MutexT ddcLRUCache< Key, Val >::mutex ( MutexT  mut)
inline

set mutex pointer

◆ size()

template<class Key, class Val>
size_t ddcLRUCache< Key, Val >::size ( void  ) const
inline

get number of currently cached items

Referenced by CDDCLeafServer::handle__status(), and NavHintCache::size().

Here is the caller graph for this function:

◆ capacity()

template<class Key, class Val>
size_t ddcLRUCache< Key, Val >::capacity ( ) const
inline

get cache capacity

◆ reserve()

template<class Key, class Val>
size_t ddcLRUCache< Key, Val >::reserve ( size_t  cap)
inline

update cache capacity; implicitly calls clean()

Referenced by NavHintCache::reserve().

Here is the caller graph for this function:

◆ lock()

template<class Key, class Val>
void ddcLRUCache< Key, Val >::lock ( )
inline

lock the cache mutex, if any

Referenced by CDDCLeafServer::handle__clear_cache(), CDDCBranchServer::handle__clear_cache(), and CCurl::perform_cached().

Here is the caller graph for this function:

◆ unlock()

template<class Key, class Val>
void ddcLRUCache< Key, Val >::unlock ( )
inline

unlock cache mutex

Referenced by CDDCLeafServer::handle__clear_cache(), CDDCBranchServer::handle__clear_cache(), and CCurl::perform_cached().

Here is the caller graph for this function:

◆ begin() [1/2]

template<class Key, class Val>
iterator ddcLRUCache< Key, Val >::begin ( )
inline

◆ end() [1/2]

template<class Key, class Val>
iterator ddcLRUCache< Key, Val >::end ( )
inline

Referenced by CCurl::perform_cached().

Here is the caller graph for this function:

◆ begin() [2/2]

template<class Key, class Val>
const_iterator ddcLRUCache< Key, Val >::begin ( ) const
inline

◆ end() [2/2]

template<class Key, class Val>
const_iterator ddcLRUCache< Key, Val >::end ( ) const
inline

◆ find() [1/2]

template<class Key, class Val>
iterator ddcLRUCache< Key, Val >::find ( const KeyT key)
inline

find cached item; returns end() if not found, does NOT update the MRU-list (non-const)

◆ lower_bound() [1/2]

template<class Key, class Val>
iterator ddcLRUCache< Key, Val >::lower_bound ( const KeyT key)
inline

find lower bound for cache key; does NOT update the MRU-list (non-const)

◆ upper_bound() [1/2]

template<class Key, class Val>
iterator ddcLRUCache< Key, Val >::upper_bound ( const KeyT key)
inline

find upper bound for cache key; does NOT update the MRU-list (non-const)

◆ find() [2/2]

template<class Key, class Val>
const_iterator ddcLRUCache< Key, Val >::find ( const KeyT key) const
inline

find cached item; returns end() if not found; does NOT update the MRU-list (const version)

◆ lower_bound() [2/2]

template<class Key, class Val>
const_iterator ddcLRUCache< Key, Val >::lower_bound ( const KeyT key) const
inline

find lower bound for cache key; does NOT update the MRU-list (const version)

◆ upper_bound() [2/2]

template<class Key, class Val>
const_iterator ddcLRUCache< Key, Val >::upper_bound ( const KeyT key) const
inline

find upper bound for cache key; does NOT update the MRU-list (const version)

◆ get()

template<class Key, class Val>
iterator ddcLRUCache< Key, Val >::get ( const KeyT key)
inline

get cached item, promoting it to MRU position if already exists; return end() if key is not found

Referenced by CCurl::perform_cached().

Here is the caller graph for this function:

◆ promote() [1/2]

template<class Key, class Val>
void ddcLRUCache< Key, Val >::promote ( const_iterator it)
inline

promote an existing item to the most-recently-used position

Referenced by ddcLRUCache< KeyT, ValT >::get().

Here is the caller graph for this function:

◆ promote() [2/2]

template<class Key, class Val>
void ddcLRUCache< Key, Val >::promote ( iterator it)
inline

promote an existing item to the most-recently-used position

◆ insert()

template<class Key, class Val>
void ddcLRUCache< Key, Val >::insert ( const KeyT key,
const ValT val 
)
inline

insert a new cache item, or promote an existing item if present.

  • implicitly calls clean().
  • prior to v2.1.11 returned an iterator to the newly inserted item
  • as of v2.1.11, no iterator is returned, since it might be invalid if capacity==0

Referenced by NavHintCache::insert(), and CCurl::perform_cached().

Here is the caller graph for this function:

Member Data Documentation

◆ m_capacity

template<class Key, class Val>
size_t ddcLRUCache< Key, Val >::m_capacity

maximum number of cached items

Referenced by ddcLRUCache< KeyT, ValT >::capacity(), and ddcLRUCache< KeyT, ValT >::reserve().

◆ m_size

template<class Key, class Val>
size_t ddcLRUCache< Key, Val >::m_size

◆ m_list

template<class Key, class Val>
ListT ddcLRUCache< Key, Val >::m_list

list of (key,val) pairs, position indicates recency of use (most recent first)

Referenced by listPos(), and ddcLRUCache< KeyT, ValT >::promote().

◆ m_map

template<class Key, class Val>
MapT ddcLRUCache< Key, Val >::m_map

maps keys to m_list iterators, used to check key existence

◆ m_mutex

template<class Key, class Val>
MutexT ddcLRUCache< Key, Val >::m_mutex

mutex pointer to use for lock() and unlock() methods

Referenced by ddcLRUCache< KeyT, ValT >::mutex().


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