Poco

template < class TKey, class TValue, class TStrategy >

class AbstractCache

Library: Foundation
Package: Cache
Header: Poco/AbstractCache.h

Description

An AbstractCache is the interface of all caches.

Member Summary

Member Functions: add, clear, doAdd, doClear, doGet, doHas, doRemove, doReplace, forceReplace, get, getAllKeys, has, initialize, remove, size, uninitialize

Types

ConstIterator

typedef typename DataHolder::const_iterator ConstIterator;

DataHolder

typedef std::map < TKey, SharedPtr < TValue > > DataHolder;

Iterator

typedef typename DataHolder::iterator Iterator;

KeySet

typedef std::set < TKey > KeySet;

Constructors

AbstractCache inline

AbstractCache();

AbstractCache inline

AbstractCache(
    const TStrategy & strat
);

Destructor

~AbstractCache virtual inline

virtual ~AbstractCache();

Member Functions

add inline

void add(
    const TKey & key,
    const TValue & val
);

Adds the key value pair to the cache. If for the key already an entry exists, it will be overwritten.

add inline

void add(
    const TKey & key,
    SharedPtr < TValue > val
);

Adds the key value pair to the cache. Note that adding a NULL SharedPtr will fail! If for the key already an entry exists, it will be overwritten.

clear inline

void clear();

Removes all elements from the cache.

forceReplace inline

void forceReplace();

Forces cache replacement. Note that Poco's cache strategy use for efficiency reason no background thread which periodically triggers cache replacement. Cache Replacement is only started when the cache is modified from outside, i.e. add is called, or when a user tries to access an cache element via get. In some cases, i.e. expire based caching where for a long time no access to the cache happens, it might be desirable to be able to trigger cache replacement manually.

get inline

SharedPtr < TValue > get(
    const TKey & key
);

Returns a SharedPtr of the value. The SharedPointer will remain valid even when cache replacement removes the element. If for the key no value exists, an empty SharedPtr is returned.

getAllKeys inline

std::set < TKey > getAllKeys();

Returns a copy of all keys stored in the cache

has inline

bool has(
    const TKey & key
) const;

Returns true if the cache contains a value for the key.

remove inline

void remove(
    const TKey & key
);

Removes an entry from the cache. If the entry is not found, the remove is ignored.

size inline

std::size_t size();

Returns the number of cached elements

doAdd protected inline

void doAdd(
    const TKey & key,
    const TValue & val
);

Adds the key value pair to the cache. If for the key already an entry exists, it will be overwritten.

doAdd protected inline

void doAdd(
    const TKey & key,
    SharedPtr < TValue > & val
);

Adds the key value pair to the cache. If for the key already an entry exists, it will be overwritten.

doClear protected inline

void doClear();

doGet protected inline

SharedPtr < TValue > doGet(
    const TKey & key
);

Returns a SharedPtr of the cache entry, returns 0 if for the key no value was found

doHas protected inline

bool doHas(
    const TKey & key
) const;

Returns true if the cache contains a value for the key

doRemove protected inline

void doRemove(
    Iterator it
);

Removes an entry from the cache. If the entry is not found the remove is ignored.

doReplace protected inline

void doReplace();

initialize protected inline

void initialize();

Sets up event registration.

uninitialize protected inline

void uninitialize();

Reverts event registration.

Variables

Add

FIFOEvent < const KeyValueArgs < TKey, TValue > > Add;

Clear

FIFOEvent < const EventArgs > Clear;

Get

FIFOEvent < const TKey > Get;

Remove

FIFOEvent < const TKey > Remove;

IsValid protected

mutable FIFOEvent < ValidArgs < TKey > > IsValid;

Replace protected

mutable FIFOEvent < KeySet > Replace;

_data protected

mutable DataHolder _data;

_mutex protected

mutable FastMutex _mutex;

_strategy protected

TStrategy _strategy;