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++>
|
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 |
|
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
-
K | The type of the cache's keys. |
V | The type of the cache's values. |
- Author
- Mark Lindner
◆ ~WriteBackCache()
◆ WriteBackCache()
◆ 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 |
( |
K |
key, |
|
|
T * |
value |
|
) |
| |
Inserts a key/value pair into the cache.
- Parameters
-
key | The key. |
value | The value. |
◆ isDirty()
bool isDirty |
( |
K |
key | ) |
const |
- Parameters
-
- Returns
- true if the value is dirty, false otherwise.
◆ lookup()
Looks up the value for a given key in the cache.
- Parameters
-
- Returns
- The value, if found, otherwise
NULL
.
◆ remove()
Removes the value for a given key from the cache.
- Parameters
-
- Returns
- true if the value was removed, false if the cache does not contain a value with the specified key.
◆ setDirty()
void setDirty |
( |
K |
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
-
key | The key. |
dirty | The dirty flag. |
◆ 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
-
The documentation for this class was generated from the following file: