Class AbstractLRUMap<K,V>
java.lang.Object
org.apache.commons.jcs3.utils.struct.AbstractLRUMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
- Direct Known Subclasses:
BlockDiskKeyStore.LRUMapSizeLimited
,IndexedDiskCache.LRUMapSizeLimited
,LRUMap
This is a simple LRUMap. It implements most of the map methods. It is not recommended that you
use any but put, get, remove, and clear.
Children can implement the processRemovedLRU method if they want to handle the removal of the least recently used item.
This class was abstracted out of the LRU Memory cache. Put, remove, and get should be thread safe. It uses a hashtable and our own double linked list.
Locking is done on the instance.
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
This removes all the items.boolean
containsKey
(Object key) Returns true if the map contains an element for the supplied key.boolean
containsValue
(Object value) This is an expensive operation that determines if the object supplied is mapped to any key.void
Dump the cache entries from first to list for debugging.void
dumpMap()
Dump the cache map for debugging.entrySet()
This returns a set of entries.This gets an element out of the map without adjusting it's position in the LRU.boolean
isEmpty()
Returns true if the map is empty.keySet()
protected void
processRemovedLRU
(K key, V value) This is called when an item is removed from the LRU.void
protected abstract boolean
int
size()
This simply returns the number of elements in the map.values()
protected void
Checks to see if all the items that should be in the cache are.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
AbstractLRUMap
public AbstractLRUMap()This creates an unbounded version. Setting the max objects will result in spooling on subsequent puts.
-
-
Method Details
-
size
This simply returns the number of elements in the map. -
clear
This removes all the items. It clears the map and the double linked list. -
isEmpty
Returns true if the map is empty. -
containsKey
Returns true if the map contains an element for the supplied key.- Specified by:
containsKey
in interfaceMap<K,
V> - See Also:
-
containsValue
This is an expensive operation that determines if the object supplied is mapped to any key.- Specified by:
containsValue
in interfaceMap<K,
V> - See Also:
-
values
-
putAll
-
get
-
getQuiet
This gets an element out of the map without adjusting it's position in the LRU. In other words, this does not count as being used. If the element is the last item in the list, it will still be the last time in the list.- Parameters:
key
-- Returns:
- Object
-
remove
-
put
-
shouldRemove
-
dumpCacheEntries
Dump the cache entries from first to list for debugging. -
dumpMap
Dump the cache map for debugging. -
verifyCache
Checks to see if all the items that should be in the cache are. Checks consistency between List and map. -
processRemovedLRU
This is called when an item is removed from the LRU. We just log some information.Children can implement this method for special behavior.
- Parameters:
key
-value
-
-
getStatistics
- Returns:
- IStats
-
entrySet
This returns a set of entries. Our LRUMapEntry is used since the value stored in the underlying map is a node in the double linked list. We wouldn't want to return this to the client, so we construct a new entry with the payload of the node.TODO we should return out own set wrapper, so we can avoid the extra object creation if it isn't necessary.
-
keySet
-