groovyx.gpars.memoize
Class LRUProtectionStorage
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<java.lang.Object,java.lang.Object>
groovyx.gpars.memoize.LRUProtectionStorage
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.Object,java.lang.Object>
public final class LRUProtectionStorage
- extends java.util.LinkedHashMap<java.lang.Object,java.lang.Object>
Protects stored resources from eviction from memory following the LRU (Last Recently Used) strategy.
If the maximum size has been reached all newly added elements will cause the oldest element to be removed from the storage
in order not to exceed the maximum capacity.
The touch method can be used to renew an element and move it to the from the LRU queue.
- Author:
- Vaclav Pech
Date: Jun 22, 2010
- See Also:
- Serialized Form
Nested classes/interfaces inherited from class java.util.AbstractMap |
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Method Summary |
java.lang.Object |
clone()
Performs a shallow clone |
java.lang.Object |
get(java.lang.Object key)
|
protected boolean |
removeEldestEntry(java.util.Map.Entry<java.lang.Object,java.lang.Object> eldest)
|
void |
touch(java.lang.Object key,
java.lang.Object value)
The touch method can be used to renew an element and move it to the from of the LRU queue. |
Methods inherited from class java.util.LinkedHashMap |
clear, containsValue |
Methods inherited from class java.util.HashMap |
containsKey, entrySet, isEmpty, keySet, put, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
equals, hashCode, toString |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
containsKey, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
maxSize
private final int maxSize
LRUProtectionStorage
public LRUProtectionStorage(int maxSize)
removeEldestEntry
protected boolean removeEldestEntry(java.util.Map.Entry<java.lang.Object,java.lang.Object> eldest)
- Overrides:
removeEldestEntry
in class java.util.LinkedHashMap<java.lang.Object,java.lang.Object>
touch
public void touch(java.lang.Object key,
java.lang.Object value)
- The touch method can be used to renew an element and move it to the from of the LRU queue.
- Parameters:
key
- The key of the element to renewvalue
- A value to newly associate with the key
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
get
in interface java.util.Map<java.lang.Object,java.lang.Object>
- Overrides:
get
in class java.util.LinkedHashMap<java.lang.Object,java.lang.Object>
clone
public java.lang.Object clone()
- Performs a shallow clone
- Overrides:
clone
in class java.util.HashMap<java.lang.Object,java.lang.Object>
- Returns:
- The cloned instance