activemq-cpp-3.9.0
decaf::util::LRUCache< K, V, HASHCODE > Class Template Reference

A Basic Least Recently Used (LRU) Cache Map. More...

#include <src/main/decaf/util/LRUCache.h>

Inheritance diagram for decaf::util::LRUCache< K, V, HASHCODE >:

Public Member Functions

 LRUCache ()
 Default constructor for an LRU Cache The default capacity is 10000. More...
 
 LRUCache (int maximumCacheSize)
 Constructs a LRUCache with a maximum capacity. More...
 
 LRUCache (int initialCapacity, int maximumCacheSize, float loadFactor, bool accessOrder)
 Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize, load factor and ordering mode. More...
 
virtual ~LRUCache ()
 
int getMaxCacheSize () const
 Gets the currently configured Max Cache Size setting. More...
 
void setMaxCacheSize (int size)
 Sets the maximum size allowed for this LRU Cache. More...
 
- Public Member Functions inherited from decaf::util::LinkedHashMap< K, V, HASHCODE >
 LinkedHashMap ()
 Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75). More...
 
 LinkedHashMap (int capacity)
 Constructs a new LinkedHashMap instance with the specified capacity. More...
 
 LinkedHashMap (int capacity, float load)
 Constructs a new. More...
 
 LinkedHashMap (int capacity, float load, bool order)
 Constructs a new. More...
 
 LinkedHashMap (const HashMap< K, V > &map)
 Constructs a new LinkedHashMap instance containing the mappings from the specified map. More...
 
virtual ~LinkedHashMap ()
 
virtual bool containsValue (const V &value) const
 Returns true if this map maps one or more keys to the specified value. More...
 
virtual void clear ()
 Removes all of the mappings from this map (optional operation). More...
 
virtual bool put (const K &key, const V &value)
 Associates the specified value with the specified key in this map (optional operation). More...
 
virtual bool put (const K &key, const V &value, V &oldValue)
 Associates the specified value with the specified key in this map (optional operation). More...
 
virtual V remove (const K &key)
 Removes the value (key/value pair) for the specified key from the map, returns a copy of the value that was mapped to the key. More...
 
virtual Set< MapEntry< K, V > > & entrySet ()
 Returns a Set view of the mappings contained in this map. More...
 
virtual const Set< MapEntry< K,
V > > & 
entrySet () const
 
virtual Set< K > & keySet ()
 Returns a Set view of the keys contained in this map. More...
 
virtual const Set< K > & keySet () const
 
virtual Collection< V > & values ()
 Returns a Collection view of the values contained in this map. More...
 
virtual const Collection< V > & values () const
 
virtual std::string toString () const
 
- Public Member Functions inherited from decaf::util::HashMap< K, V, HASHCODE >
 HashMap ()
 Creates a new empty HashMap with default configuration settings. More...
 
 HashMap (int capacity)
 Constructs a new HashMap instance with the specified capacity. More...
 
 HashMap (int capacity, float loadFactor)
 Constructs a new HashMap instance with the specified capacity. More...
 
 HashMap (const HashMap< K, V > &map)
 Creates a new HashMap with default configuration settings and fills it with the contents of the given source Map instance. More...
 
 HashMap (const Map< K, V > &map)
 Creates a new HashMap with default configuration settings and fills it with the contents of the given source Map instance. More...
 
virtual ~HashMap ()
 
HashMap< K, V > & operator= (const Map< K, V > &other)
 
HashMap< K, V > & operator= (const HashMap< K, V > &other)
 
bool operator== (const Map< K, V > &other) const
 
bool operator!= (const Map< K, V > &other) const
 
virtual bool isEmpty () const
 
virtual int size () const
 
virtual bool containsKey (const K &key) const
 Returns true if this map contains a mapping for the specified key. More...
 
virtual V & get (const K &key)
 Gets the value mapped to the specified key in the Map. More...
 
virtual const V & get (const K &key) const
 Gets the value mapped to the specified key in the Map. More...
 
virtual void putAll (const Map< K, V > &map)
 Copies all of the mappings from the specified map to this map (optional operation). More...
 
virtual bool equals (const Map< K, V > &source) const
 Compares the specified object with this map for equality. More...
 
virtual void copy (const Map< K, V > &source)
 Copies the content of the source map into this map. More...
 
- Public Member Functions inherited from decaf::util::AbstractMap< K, V >
 AbstractMap ()
 
 AbstractMap (const Map< K, V > &map DECAF_UNUSED)
 
 AbstractMap (const AbstractMap< K, V > &map DECAF_UNUSED)
 
virtual ~AbstractMap ()
 
virtual void lock ()
 Locks the object. More...
 
virtual bool tryLock ()
 Attempts to Lock the object, if the lock is already held by another thread than this method returns false. More...
 
virtual void unlock ()
 Unlocks the object. More...
 
virtual void wait ()
 Waits on a signal from this object, which is generated by a call to Notify. More...
 
virtual void wait (long long millisecs)
 Waits on a signal from this object, which is generated by a call to Notify. More...
 
virtual void wait (long long millisecs, int nanos)
 Waits on a signal from this object, which is generated by a call to Notify. More...
 
virtual void notify ()
 Signals a waiter on this object that it can now wake up and continue. More...
 
virtual void notifyAll ()
 Signals the waiters on this object that it can now wake up and continue. More...
 
- Public Member Functions inherited from decaf::util::Map< K, V >
 Map ()
 Default constructor - does nothing. More...
 
virtual ~Map ()
 
- Public Member Functions inherited from decaf::util::concurrent::Synchronizable
virtual ~Synchronizable ()
 

Protected Member Functions

virtual bool removeEldestEntry (const MapEntry< K, V > &eldest DECAF_UNUSED)
 This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member. More...
 
- Protected Member Functions inherited from decaf::util::LinkedHashMap< K, V, HASHCODE >
virtual void onEviction (const MapEntry< K, V > &eldest DECAF_UNUSED)
 This method is called when the removeEldestEntry has returned true and a MapEntry is about to be removed from the Map. More...
 
virtual LinkedHashMapEntry * getEntry (const K &key) const
 
virtual HashMap< K, V,
HASHCODE >::HashMapEntry
createEntry (const K &key, int index, const V &value)
 
virtual HashMap< K, V,
HASHCODE >::HashMapEntry
createHashedEntry (const K &key, int index, int hash)
 
void linkEntry (LinkedHashMapEntry *entry)
 
virtual bool putImpl (const K &key, const V &value)
 
virtual bool putImpl (const K &key, const V &value, V &oldValue)
 
- Protected Member Functions inherited from decaf::util::HashMap< K, V, HASHCODE >
void putAllImpl (const Map< K, V > &map)
 
HashMapEntryfindKeyEntry (const K &key, int index, int keyHash) const
 
void rehash (int capacity)
 
void rehash ()
 
void removeEntry (HashMapEntry *entry)
 
HashMapEntryremoveEntry (const K &key)
 

Protected Attributes

int maxCacheSize
 
- Protected Attributes inherited from decaf::util::HashMap< K, V, HASHCODE >
HASHCODE hashFunc
 The Hash Code generator for this map's keys. More...
 
int elementCount
 
decaf::lang::ArrayPointer
< HashMapEntry * > 
elementData
 
int modCount
 
float loadFactor
 
int threshold
 
decaf::lang::Pointer
< HashMapEntrySet
cachedEntrySet
 
decaf::lang::Pointer
< HashMapKeySet
cachedKeySet
 
decaf::lang::Pointer
< HashMapValueCollection
cachedValueCollection
 
decaf::lang::Pointer
< ConstHashMapEntrySet
cachedConstEntrySet
 
decaf::lang::Pointer
< ConstHashMapKeySet
cachedConstKeySet
 
decaf::lang::Pointer
< ConstHashMapValueCollection
cachedConstValueCollection
 
- Protected Attributes inherited from decaf::util::AbstractMap< K, V >
util::concurrent::Mutex mutex
 

Detailed Description

template<typename K, typename V, typename HASHCODE = HashCode<K>>
class decaf::util::LRUCache< K, V, HASHCODE >

A Basic Least Recently Used (LRU) Cache Map.

This LRUCache implements the LinkedHashMap class so all the standard Map operations are provided. When the sive of this LRUCache map exceeds the specified maxCacheSize value then by default the oldest entry is evicted from the Cache.

Subclasses can override the LinkedHashMap::onEviction method to perform custom cache eviction processing.

Since
1.0

Constructor & Destructor Documentation

template<typename K , typename V , typename HASHCODE = HashCode<K>>
decaf::util::LRUCache< K, V, HASHCODE >::LRUCache ( )
inline

Default constructor for an LRU Cache The default capacity is 10000.

template<typename K , typename V , typename HASHCODE = HashCode<K>>
decaf::util::LRUCache< K, V, HASHCODE >::LRUCache ( int  maximumCacheSize)
inline

Constructs a LRUCache with a maximum capacity.

Parameters
maximumCacheSizeThe maximum number of cached entries before eviction begins.
template<typename K , typename V , typename HASHCODE = HashCode<K>>
decaf::util::LRUCache< K, V, HASHCODE >::LRUCache ( int  initialCapacity,
int  maximumCacheSize,
float  loadFactor,
bool  accessOrder 
)
inline

Constructs an empty LRUCache instance with the specified initial capacity, maximumCacheSize, load factor and ordering mode.

Parameters
initialCapacityThe initial capacity of the LRUCache.
maximumCacheSizeThe maximum number of cached entries before eviction begins.
loadFactorthe load factor. The initial load factor for this LRUCache.
accessOrderThe ordering mode - true for access-order, false for insertion-order.
Exceptions
IllegalArgumentExceptionif the initial capacity is negative or the load factor is non-positive.
template<typename K , typename V , typename HASHCODE = HashCode<K>>
virtual decaf::util::LRUCache< K, V, HASHCODE >::~LRUCache ( )
inlinevirtual

Member Function Documentation

template<typename K , typename V , typename HASHCODE = HashCode<K>>
int decaf::util::LRUCache< K, V, HASHCODE >::getMaxCacheSize ( ) const
inline

Gets the currently configured Max Cache Size setting.

Returns
the current max cache size value.

References decaf::util::LRUCache< K, V, HASHCODE >::maxCacheSize.

template<typename K , typename V , typename HASHCODE = HashCode<K>>
virtual bool decaf::util::LRUCache< K, V, HASHCODE >::removeEldestEntry ( const MapEntry< K, V > &eldest  DECAF_UNUSED)
inlineprotectedvirtual

This method is queried from the put and putAll methods to check if the eldest member of the map should be deleted before adding the new member.

If this map was created with accessOrder = true, then the result of removeEldestEntry is assumed to be false.

Parameters
eldestThe entry to check if it should be removed.
Returns
true if the eldest member should be removed.

Reimplemented from decaf::util::LinkedHashMap< K, V, HASHCODE >.

References decaf::util::LRUCache< K, V, HASHCODE >::maxCacheSize, and decaf::util::HashMap< K, V, HASHCODE >::size().

template<typename K , typename V , typename HASHCODE = HashCode<K>>
void decaf::util::LRUCache< K, V, HASHCODE >::setMaxCacheSize ( int  size)
inline

Sets the maximum size allowed for this LRU Cache.

Parameters
sizeThe new maximum cache size setting.
Exceptions
IllegalArgumentExceptionis size is less than or equal to zero.

References decaf::util::LRUCache< K, V, HASHCODE >::maxCacheSize, and decaf::util::HashMap< K, V, HASHCODE >::size().

Field Documentation

template<typename K , typename V , typename HASHCODE = HashCode<K>>
int decaf::util::LRUCache< K, V, HASHCODE >::maxCacheSize
protected

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