ddc
|
generic least-recently-used cache template More...
#include <LRUCache.h>
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, ValT > | ItemT |
elementary data item: (key,val) pair More... | |
typedef std::list< ItemT > | ListT |
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... | |
generic least-recently-used cache template
typedef Key ddcLRUCache< Key, Val >::KeyT |
key type
typedef Val ddcLRUCache< Key, Val >::ValT |
value type
typedef pthread_mutex_t* ddcLRUCache< Key, Val >::MutexT |
mutex type (pthreads enabled)
typedef std::pair<KeyT,ValT> ddcLRUCache< Key, Val >::ItemT |
elementary data item: (key,val) pair
typedef std::list<ItemT> ddcLRUCache< Key, Val >::ListT |
list of (key,val) pairs, position indicates recency of use (most recent first)
typedef std::map<KeyT, typename ListT::iterator> ddcLRUCache< Key, Val >::MapT |
maps keys to lru-list iterators, used to check key existence
typedef MapT::iterator ddcLRUCache< Key, Val >::iterator |
iterator wraps MapT::iterator (~ pair< KeyT, pair<KeyT,ValT>* > *)
typedef MapT::const_iterator ddcLRUCache< Key, Val >::const_iterator |
const_iterator wraps MapT::const_iterator
|
inline |
default constructor
|
inline |
clear all cached items (no implicit locks)
Referenced by NavHintCache::clear(), CDDCLeafServer::handle__clear_cache(), and CDDCBranchServer::handle__clear_cache().
|
inline |
drop least recently used cache items until size <= capacity
Referenced by ddcLRUCache< KeyT, ValT >::insert(), and ddcLRUCache< KeyT, ValT >::reserve().
|
inline |
get mutex pointer
|
inline |
set mutex pointer
|
inline |
get number of currently cached items
Referenced by CDDCLeafServer::handle__status(), and NavHintCache::size().
|
inline |
get cache capacity
|
inline |
update cache capacity; implicitly calls clean()
Referenced by NavHintCache::reserve().
|
inline |
lock the cache mutex, if any
Referenced by CDDCLeafServer::handle__clear_cache(), CDDCBranchServer::handle__clear_cache(), and CCurl::perform_cached().
|
inline |
unlock cache mutex
Referenced by CDDCLeafServer::handle__clear_cache(), CDDCBranchServer::handle__clear_cache(), and CCurl::perform_cached().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
find cached item; returns end() if not found, does NOT update the MRU-list (non-const)
|
inline |
find lower bound for cache key; does NOT update the MRU-list (non-const)
|
inline |
find upper bound for cache key; does NOT update the MRU-list (non-const)
|
inline |
find cached item; returns end() if not found; does NOT update the MRU-list (const version)
|
inline |
find lower bound for cache key; does NOT update the MRU-list (const version)
|
inline |
find upper bound for cache key; does NOT update the MRU-list (const version)
|
inline |
get cached item, promoting it to MRU position if already exists; return end() if key is not found
Referenced by CCurl::perform_cached().
|
inline |
promote an existing item to the most-recently-used position
Referenced by ddcLRUCache< KeyT, ValT >::get().
|
inline |
promote an existing item to the most-recently-used position
|
inline |
insert a new cache item, or promote an existing item if present.
Referenced by NavHintCache::insert(), and CCurl::perform_cached().
size_t ddcLRUCache< Key, Val >::m_capacity |
maximum number of cached items
Referenced by ddcLRUCache< KeyT, ValT >::capacity(), and ddcLRUCache< KeyT, ValT >::reserve().
size_t ddcLRUCache< Key, Val >::m_size |
current number of cached items
Referenced by ddcLRUCache< KeyT, ValT >::clean(), ddcLRUCache< KeyT, ValT >::insert(), and ddcLRUCache< KeyT, ValT >::size().
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().
MapT ddcLRUCache< Key, Val >::m_map |
maps keys to m_list iterators, used to check key existence
MutexT ddcLRUCache< Key, Val >::m_mutex |
mutex pointer to use for lock() and unlock() methods
Referenced by ddcLRUCache< KeyT, ValT >::mutex().