activemq-cpp-3.9.5
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.
 
 LRUCache (int maximumCacheSize)
 Constructs a LRUCache with a maximum capacity.
 
 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.
 
virtual ~LRUCache ()
 
int getMaxCacheSize () const
 Gets the currently configured Max Cache Size setting.
 
void setMaxCacheSize (int size)
 Sets the maximum size allowed for this LRU Cache.
 
- 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).
 
 LinkedHashMap (int capacity)
 Constructs a new LinkedHashMap instance with the specified capacity.
 
 LinkedHashMap (int capacity, float load)
 Constructs a new LinkedHashMap instance with the specified capacity and load factor.
 
 LinkedHashMap (int capacity, float load, bool order)
 Constructs a new LinkedHashMap instance with the specified capacity, load factor and a flag specifying the ordering behavior.
 
 LinkedHashMap (const HashMap< K, V > &map)
 Constructs a new LinkedHashMap instance containing the mappings from the specified map.
 
virtual ~LinkedHashMap ()
 
virtual bool containsValue (const V &value) const
 Returns true if this map maps one or more keys to the specified value.
 
virtual void clear ()
 Removes all of the mappings from this map (optional operation).
 
virtual bool put (const K &key, const V &value)
 Associates the specified value with the specified key in this map (optional operation).
 
virtual bool put (const K &key, const V &value, V &oldValue)
 Associates the specified value with the specified key in this map (optional operation).
 
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.
 
virtual Set< MapEntry< K, V > > & entrySet ()
 Returns a Set view of the mappings contained in this map.
 
virtual const Set< MapEntry< K, V > > & entrySet () const
 
virtual Set< K > & keySet ()
 Returns a Set view of the keys contained in this map.
 
virtual const Set< K > & keySet () const
 
virtual Collection< V > & values ()
 Returns a Collection view of the values contained in this map.
 
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.
 
 HashMap (int capacity)
 Constructs a new HashMap instance with the specified capacity.
 
 HashMap (int capacity, float loadFactor)
 Constructs a new HashMap instance with the specified capacity.
 
 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.
 
 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.
 
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.
 
virtual V & get (const K &key)
 Gets the value mapped to the specified key in the Map.
 
virtual const V & get (const K &key) const
 Gets the value mapped to the specified key in the Map.
 
virtual void putAll (const Map< K, V > &map)
 Copies all of the mappings from the specified map to this map (optional operation).
 
virtual bool equals (const Map< K, V > &source) const
 Compares the specified object with this map for equality.
 
virtual void copy (const Map< K, V > &source)
 Copies the content of the source map into this map.
 
- 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.
 
virtual bool tryLock ()
 Attempts to Lock the object, if the lock is already held by another thread than this method returns false.
 
virtual void unlock ()
 Unlocks the object.
 
virtual void wait ()
 Waits on a signal from this object, which is generated by a call to Notify.
 
virtual void wait (long long millisecs)
 Waits on a signal from this object, which is generated by a call to Notify.
 
virtual void wait (long long millisecs, int nanos)
 Waits on a signal from this object, which is generated by a call to Notify.
 
virtual void notify ()
 Signals a waiter on this object that it can now wake up and continue.
 
virtual void notifyAll ()
 Signals the waiters on this object that it can now wake up and continue.
 
- Public Member Functions inherited from decaf::util::Map< K, V >
 Map ()
 Default constructor - does nothing.
 
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.
 
- 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.
 
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.
 
int elementCount
 
decaf::lang::ArrayPointer< HashMapEntry * > elementData
 
int modCount
 
float loadFactor
 
int threshold
 
decaf::lang::Pointer< HashMapEntrySetcachedEntrySet
 
decaf::lang::Pointer< HashMapKeySetcachedKeySet
 
decaf::lang::Pointer< HashMapValueCollectioncachedValueCollection
 
decaf::lang::Pointer< ConstHashMapEntrySetcachedConstEntrySet
 
decaf::lang::Pointer< ConstHashMapKeySetcachedConstKeySet
 
decaf::lang::Pointer< ConstHashMapValueCollectioncachedConstValueCollection
 
- 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

◆ LRUCache() [1/3]

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.

References decaf::util::LinkedHashMap< K, V, HASHCODE >::LinkedHashMap(), and maxCacheSize.

◆ LRUCache() [2/3]

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.

References decaf::util::LinkedHashMap< K, V, HASHCODE >::LinkedHashMap(), and maxCacheSize.

◆ LRUCache() [3/3]

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.

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

◆ ~LRUCache()

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

Member Function Documentation

◆ getMaxCacheSize()

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 maxCacheSize.

◆ removeEldestEntry()

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::HashMap< K, V, HASHCODE >::size().

◆ setMaxCacheSize()

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::HashMap< K, V, HASHCODE >::size().

Field Documentation

◆ maxCacheSize

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: