23 #ifndef __ccxx_Cache_hxx 24 #define __ccxx_Cache_hxx 46 template<
typename K,
typename T>
class Cache 69 void put(K key, T* item);
84 {
return(this->
get(key)); }
124 {
return(_maxSize); }
137 {
return(_size == 0); }
151 virtual void onRemove(K key, T* item);
174 bool operator()(
const Link* key1,
const Link* key2)
const 175 {
return(key1->key < key2->key); }
179 void _unlink(Link* link)
const;
180 void _link(Link* link)
const;
182 typedef std::map<Link*, T*, KeyCompare> MapType;
183 mutable MapType _map;
188 #include <commonc++/CacheImpl.h++> 192 #endif // __ccxx_Cache_hxx virtual ~Cache()
Destructor.
void put(K key, T *item)
Put an item in the cache.
T * operator[](K key) const
Index operator.
Definition: Cache.h++:83
uint_t getSize() const
Return the current size of the cache, i.e., the number of items in the cache.
Definition: Cache.h++:130
T * take(K key)
Remove an item from the cache, and return the item.
bool isEmpty() const
Test if the cache is empty.
Definition: Cache.h++:136
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
uint_t getMaxSize() const
Return the maximum size of the cache, i.e., the maximum number of items that the cache can hold...
Definition: Cache.h++:123
virtual void onRemove(K key, T *item)
A method that is called whenever an item is being removed from the cache, but just before it has been...
Cache(uint_t maxSize)
Construct a new cache with the given maximum size.
bool contains(K key) const
Test if the cache contains an item with the specified key.
A general-purpose LRU-cache with a maximum capacity.
Definition: Cache.h++:46
void clear()
Remove all items from the cache.
Definition: AllocationMap.c++:25