Quark  0.1
WriteBackCache< K, T > Class Template Referenceabstract

An abstract LRU cache implementation that tracks modifications to the cached items and performs writes of modified items to the cache source on demand. More...

#include <WriteBackCache.h++>

Public Member Functions

virtual ~WriteBackCache ()
 Destructor. More...
 
void insert (K key, T *value)
 Inserts a key/value pair into the cache. More...
 
T * lookup (K key)
 Looks up the value for a given key in the cache. More...
 
bool remove (K key)
 Removes the value for a given key from the cache. More...
 
bool sync ()
 Synchronizes the cache contents with the cache source. More...
 
bool flush ()
 Flushes the cache. More...
 
void setDirty (K key, bool dirty)
 Sets the "dirty" flag for the value for a given key in the cache. More...
 
bool isDirty (K key) const
 

Protected Member Functions

 WriteBackCache (int maxCapacity)
 Constructs a new WriteBackCache with the given maximum capacity. More...
 
virtual void write (const T *value)=0
 Writes a cached value to the cache source. More...
 

Detailed Description

template<typename K, class T>
class quark::util::WriteBackCache< K, T >

An abstract LRU cache implementation that tracks modifications to the cached items and performs writes of modified items to the cache source on demand.

Subclasses must provide a suitable public constructor and implement the write() method. The cache takes ownership of its values.

Template Parameters
KThe type of the cache's keys.
VThe type of the cache's values.
Author
Mark Lindner

Constructor & Destructor Documentation

◆ ~WriteBackCache()

virtual ~WriteBackCache ( )
virtual

Destructor.

◆ WriteBackCache()

WriteBackCache ( int  maxCapacity)
protected

Constructs a new WriteBackCache with the given maximum capacity.

Member Function Documentation

◆ flush()

bool flush ( )

Flushes the cache.

Any values that are marked "dirty" will be written to the cache source via a call to write(). Then the cache will be cleared and all of its values explicitly deleted.

Returns
true if any writes occurred, false otherwise.

◆ insert()

void insert ( key,
T *  value 
)

Inserts a key/value pair into the cache.

Parameters
keyThe key.
valueThe value.

◆ isDirty()

bool isDirty ( key) const
Parameters
keyThe key.
Returns
true if the value is dirty, false otherwise.

◆ lookup()

T* lookup ( key)

Looks up the value for a given key in the cache.

Parameters
keyThe key.
Returns
The value, if found, otherwise NULL.

◆ remove()

bool remove ( key)

Removes the value for a given key from the cache.

Parameters
keyThe key.
Returns
true if the value was removed, false if the cache does not contain a value with the specified key.

◆ setDirty()

void setDirty ( key,
bool  dirty 
)

Sets the "dirty" flag for the value for a given key in the cache.

A "dirty" value is one that has been modified and needs to be written back to the cache source eventually.

Parameters
keyThe key.
dirtyThe dirty flag.

◆ sync()

bool sync ( )

Synchronizes the cache contents with the cache source.

Any values that are marked "dirty" will be written to the cache source via a call to write(), and will then have their "dirty" flag cleared.

Returns
true if any writes occurred, false otherwise.

◆ write()

virtual void write ( const T *  value)
protectedpure virtual

Writes a cached value to the cache source.

Parameters
valueThe value to write.

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