libcommonc++
0.7
|
An abstract base class for a general-purpose LRU-cache with a maximum capacity. More...
#include <AbstractCache.h++>
Public Member Functions | |
virtual | ~AbstractCache () |
Destructor. More... | |
virtual T * | get (const K &key)=0 |
Look up an item in the cache. More... | |
T * | operator[] (const K &key) |
Index operator. More... | |
bool | contains (const K &key) const |
Test if the cache contains an item with the specified key. More... | |
virtual void | clear () |
Remove all items from the cache. More... | |
uint_t | getMaxSize () const |
Return the maximum size of the cache, i.e., the maximum number of items that the cache can hold. More... | |
uint_t | getSize () const |
Return the current size of the cache, i.e., the number of items in the cache. More... | |
bool | isEmpty () const |
Test if the cache is empty. More... | |
bool | isFull () const |
Test if the cache is full. More... | |
Protected Member Functions | |
AbstractCache (uint_t maxSize) | |
Construct a new cache with the given maximum size. More... | |
virtual void | onRemove (const K &key, T *item) |
A method that is called whenever an item is being removed from the cache, but just before it has been deleted. More... | |
An abstract base class for a general-purpose LRU-cache with a maximum capacity.
The cache maintains a key/value map, and takes ownership of its items. If the cache is at full capacity when a new item is inserted, the least recently accessed item is removed to make room.
Whenever an item is being permanently removed from the cache (e.g., as a result of a call to clear()
or the destructor) the onRemove()
method is called just before the item is deleted.
|
virtual |
Destructor.
Clears the cache.
|
protected |
Construct a new cache with the given maximum size.
maxSize | The maximum number of items that the cache will hold. If 0, the value 1 will be used instead. |
|
virtual |
Remove all items from the cache.
Reimplemented in StaticCache< K, T >.
bool contains | ( | const K & | key | ) | const |
Test if the cache contains an item with the specified key.
key | The key. |
|
pure virtual |
Look up an item in the cache.
key | The item key. |
Implemented in DynamicCache< K, T >, and StaticCache< K, T >.
|
inline |
Return the maximum size of the cache, i.e., the maximum number of items that the cache can hold.
|
inline |
Return the current size of the cache, i.e., the number of items in the cache.
|
inline |
Test if the cache is empty.
|
inline |
Test if the cache is full.
|
protectedvirtual |
A method that is called whenever an item is being removed from the cache, but just before it has been deleted.
The default implementation is a no-op. Subclasses may override this method to do any necessary cleanup of the item before it is deleted, but should not delete the item itself.
key | The key for the item being removed. |
item | The item being removed. |
|
inline |
Index operator.
Equivalent to get()
.