oasys::Cache< _Key, _Val, _EvictFcn > Class Template Reference

#include <Cache.h>

Inheritance diagram for oasys::Cache< _Key, _Val, _EvictFcn >:

oasys::Logger

List of all members.


Detailed Description

template<typename _Key, typename _Val, typename _EvictFcn>
class oasys::Cache< _Key, _Val, _EvictFcn >

Generic cache implementation. To simplify the contract,

The _EvictFcn is required to implement the signature:

void (*)(_Key& k, _Val& v);

Definition at line 38 of file Cache.h.


Public Types

typedef LRUList
< LRUListEnt
CacheList
typedef std::map
< _Key, typename
CacheList::iterator > 
CacheMap

Public Member Functions

 Cache (const char *logpath, size_t max)
bool get (const _Key &key, _Val *valp, bool pin=false, typename CacheList::iterator *iter=NULL)
bool get_and_pin (const _Key &key, _Val *valp)
void unpin (const _Key &key)
bool put_and_pin (const _Key &key, const _Val &val, typename CacheList::iterator *iter=NULL)
void evict (const _Key &key)
void evict_all ()

Private Member Functions

bool evict_last ()

Private Attributes

SpinLock lock_
CacheList cache_list_
CacheMap cache_map_
size_t max_

Classes

struct  LRUListEnt
class  ScopedUnpin

Member Typedef Documentation

template<typename _Key, typename _Val, typename _EvictFcn>
typedef LRUList<LRUListEnt> oasys::Cache< _Key, _Val, _EvictFcn >::CacheList

Definition at line 55 of file Cache.h.

template<typename _Key, typename _Val, typename _EvictFcn>
typedef std::map<_Key, typename CacheList::iterator> oasys::Cache< _Key, _Val, _EvictFcn >::CacheMap

Definition at line 56 of file Cache.h.


Constructor & Destructor Documentation

template<typename _Key, typename _Val, typename _EvictFcn>
oasys::Cache< _Key, _Val, _EvictFcn >::Cache ( const char *  logpath,
size_t  max 
) [inline]

Constructor that takes the cache limit.

Definition at line 61 of file Cache.h.


Member Function Documentation

template<typename _Key, typename _Val, typename _EvictFcn>
bool oasys::Cache< _Key, _Val, _EvictFcn >::get ( const _Key &  key,
_Val *  valp,
bool  pin = false,
typename CacheList::iterator *  iter = NULL 
) [inline]

Get an item from the cache and optionally pin it.

Returns:
whether or not the value is in the cache, and assign *valp to the value.

Definition at line 70 of file Cache.h.

References oasys::Cache< _Key, _Val, _EvictFcn >::cache_list_, oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_, ExamineDump::l, oasys::Cache< _Key, _Val, _EvictFcn >::lock_, log_debug, and oasys::LRUList< _Type >::move_to_back().

template<typename _Key, typename _Val, typename _EvictFcn>
bool oasys::Cache< _Key, _Val, _EvictFcn >::get_and_pin ( const _Key &  key,
_Val *  valp 
) [inline]

Syntactic sugar.

Definition at line 105 of file Cache.h.

template<typename _Key, typename _Val, typename _EvictFcn>
void oasys::Cache< _Key, _Val, _EvictFcn >::unpin ( const _Key &  key  )  [inline]

Unpin the val referenced by _Key.

Definition at line 113 of file Cache.h.

References ASSERT, oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_, ExamineDump::l, oasys::Cache< _Key, _Val, _EvictFcn >::lock_, and log_debug.

Referenced by oasys::Cache< _Key, _Val, _EvictFcn >::ScopedUnpin::~ScopedUnpin().

template<typename _Key, typename _Val, typename _EvictFcn>
bool oasys::Cache< _Key, _Val, _EvictFcn >::put_and_pin ( const _Key &  key,
const _Val &  val,
typename CacheList::iterator *  iter = NULL 
) [inline]

Put an val in the file cache which may evict unpinned vals. Also pin the val that was just put into the cache.

Returns:
true if the item successfully was put in the cache, false if there was a collision on the key.

Definition at line 135 of file Cache.h.

References oasys::Cache< _Key, _Val, _EvictFcn >::cache_list_, oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_, oasys::Cache< _Key, _Val, _EvictFcn >::evict_last(), ExamineDump::l, oasys::Cache< _Key, _Val, _EvictFcn >::lock_, log_debug, and oasys::Cache< _Key, _Val, _EvictFcn >::max_.

template<typename _Key, typename _Val, typename _EvictFcn>
void oasys::Cache< _Key, _Val, _EvictFcn >::evict ( const _Key &  key  )  [inline]

Evict the given key, calling the _EvictFcn on it.

Definition at line 176 of file Cache.h.

References ASSERT, oasys::Cache< _Key, _Val, _EvictFcn >::cache_list_, oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_, ExamineDump::l, oasys::Cache< _Key, _Val, _EvictFcn >::lock_, and log_debug.

template<typename _Key, typename _Val, typename _EvictFcn>
void oasys::Cache< _Key, _Val, _EvictFcn >::evict_all (  )  [inline]

Evict all of the cached vals.

Definition at line 201 of file Cache.h.

References oasys::Cache< _Key, _Val, _EvictFcn >::cache_list_, oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_, ExamineDump::l, oasys::Cache< _Key, _Val, _EvictFcn >::lock_, log_debug, and log_warn.

template<typename _Key, typename _Val, typename _EvictFcn>
bool oasys::Cache< _Key, _Val, _EvictFcn >::evict_last (  )  [inline, private]

Search from the beginning of the list and throw out a single, unpinned val.

Returns:
whether or not evict succeeded

Definition at line 259 of file Cache.h.

References oasys::Cache< _Key, _Val, _EvictFcn >::cache_list_, oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_, log_debug, and log_warn.

Referenced by oasys::Cache< _Key, _Val, _EvictFcn >::put_and_pin().


Member Data Documentation

template<typename _Key, typename _Val, typename _EvictFcn>
SpinLock oasys::Cache< _Key, _Val, _EvictFcn >::lock_ [private]

Definition at line 246 of file Cache.h.

Referenced by oasys::Cache< _Key, _Val, _EvictFcn >::evict(), oasys::Cache< _Key, _Val, _EvictFcn >::evict_all(), oasys::Cache< _Key, _Val, _EvictFcn >::get(), oasys::Cache< _Key, _Val, _EvictFcn >::put_and_pin(), and oasys::Cache< _Key, _Val, _EvictFcn >::unpin().

template<typename _Key, typename _Val, typename _EvictFcn>
CacheList oasys::Cache< _Key, _Val, _EvictFcn >::cache_list_ [private]

Definition at line 248 of file Cache.h.

Referenced by oasys::Cache< _Key, _Val, _EvictFcn >::evict(), oasys::Cache< _Key, _Val, _EvictFcn >::evict_all(), oasys::Cache< _Key, _Val, _EvictFcn >::evict_last(), oasys::Cache< _Key, _Val, _EvictFcn >::get(), and oasys::Cache< _Key, _Val, _EvictFcn >::put_and_pin().

template<typename _Key, typename _Val, typename _EvictFcn>
CacheMap oasys::Cache< _Key, _Val, _EvictFcn >::cache_map_ [private]

Definition at line 249 of file Cache.h.

Referenced by oasys::Cache< _Key, _Val, _EvictFcn >::evict(), oasys::Cache< _Key, _Val, _EvictFcn >::evict_all(), oasys::Cache< _Key, _Val, _EvictFcn >::evict_last(), oasys::Cache< _Key, _Val, _EvictFcn >::get(), oasys::Cache< _Key, _Val, _EvictFcn >::put_and_pin(), and oasys::Cache< _Key, _Val, _EvictFcn >::unpin().

template<typename _Key, typename _Val, typename _EvictFcn>
size_t oasys::Cache< _Key, _Val, _EvictFcn >::max_ [private]

Definition at line 251 of file Cache.h.

Referenced by oasys::Cache< _Key, _Val, _EvictFcn >::put_and_pin().


The documentation for this class was generated from the following file:
Generated on Sat Sep 8 08:36:26 2007 for DTN Reference Implementation by  doxygen 1.5.3