mace::LRUCache< K, D > Class Template Reference

#include <LRUCache.h>

List of all members.


Detailed Description

template<typename K, typename D>
class mace::LRUCache< K, D >

Provides a cache with a least recently used replacement policy and a map like interface.

The add methods will evict the least recently used non-dirty key. If all the indices are dirty, then the least recently used dirty key will be evicted.

Use timeouts with caution---if a dirty entry expires, it will be deleted the next time containsKey is called for its entry. Because dirty entries may be deleted before they have a chance to be cleared, it is advised to not use a timeout when storing dirty data in the cache.

Warning:
you MUST call containsKey and check that the result is true before calling get, operator[], or obtain the key by getLastDirtyKey

Definition at line 68 of file LRUCache.h.


Public Member Functions

 LRUCache (unsigned capacity=32, time_t timeout=0)
 create a new cache with the specified capacity.
void addDirty (const K &index, const D &buf)
 add a new entry to the cache, mark as dirty
void add (const K &index, const D &buf, bool dirty=false)
 add a new entry to the cache, set dirty as specified
void remove (const K &index)
 removes the entry from the cache
bool get (const K &index, D &data)
 lookup the value for the given key
D & get (const K &index)
 lookup the value for the given key
D & operator[] (const K &index)
 lookup the value for the given key
bool isFullDirty () const
 true if the cache is full, and all entries are dirty
bool hasDirty () const
 true if any entries are dirty
const K & getLastDirtyKey () const
 return the least recently accessed dirty key
D & getLastDirty () const
 return the least recently accessed dirty value
bool getLastDirty (K &k, D &d) const
 return the least recently accessed dirty key and value
void clearLastDirty ()
 clear the dirty bit for the key returned by getLastDirtyEntry()
void clearDirty (const K &index)
 clear the dirty bit for the given key
D & getDirty (const K &index)
 get the value of the given key

Constructor & Destructor Documentation

template<typename K, typename D>
mace::LRUCache< K, D >::LRUCache ( unsigned  capacity = 32,
time_t  timeout = 0 
) [inline]

create a new cache with the specified capacity.

If a timeout is given, then entries will be expired after the specified timeout.

Definition at line 98 of file LRUCache.h.


Member Function Documentation

template<typename K, typename D>
void mace::LRUCache< K, D >::addDirty ( const K &  index,
const D &  buf 
) [inline]

add a new entry to the cache, mark as dirty

The add methods will evict the least recently used non-dirty key. If all the indices are dirty, then the least recently used dirty key will be evicted.

Definition at line 128 of file LRUCache.h.

template<typename K, typename D>
void mace::LRUCache< K, D >::add ( const K &  index,
const D &  buf,
bool  dirty = false 
) [inline]

add a new entry to the cache, set dirty as specified

The add methods will evict the least recently used non-dirty key. If all the indices are dirty, then the least recently used dirty key will be evicted.

Definition at line 139 of file LRUCache.h.

template<typename K, typename D>
bool mace::LRUCache< K, D >::get ( const K &  index,
D &  data 
) [inline]

lookup the value for the given key

Warning:
you MUST call containsKey and check that the result is true before calling get, operator[], or obtain the key by getLastDirtyKey

Definition at line 240 of file LRUCache.h.

Referenced by BufferedBlockManager::getBlock().

template<typename K, typename D>
D& mace::LRUCache< K, D >::get ( const K &  index  )  [inline]

lookup the value for the given key

Warning:
you MUST call containsKey and check that the result is true before calling get, operator[], or obtain the key by getLastDirtyKey

Definition at line 258 of file LRUCache.h.

template<typename K, typename D>
D& mace::LRUCache< K, D >::operator[] ( const K &  index  )  [inline]

lookup the value for the given key

Warning:
you MUST call containsKey and check that the result is true before calling get, operator[], or obtain the key by getLastDirtyKey

Definition at line 273 of file LRUCache.h.

template<typename K, typename D>
D& mace::LRUCache< K, D >::getDirty ( const K &  index  )  [inline]

get the value of the given key

does not adjust access status: the key remains in its current position with respect to how recently it was used

Definition at line 356 of file LRUCache.h.


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

Generated on Sat Oct 4 21:30:38 2008 for Mace Library by  doxygen 1.5.5