Class CachingMap<T>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<String,SoftReference<T>>
org.apache.sling.scripting.core.impl.helper.CachingMap<T>
- Type Parameters:
T
- the type to whichSoftReference
s will be kept
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
SoftReference<T>>
The CachingMap
class offers an implementation of a LinkedHashMap
that can be used for caches. The maps' values are
SoftReference
s, such that garbage collection can be performed on the cache, if needed.
Read / write operations are NOT synchronised.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionCachingMap
(int capacity) Creates a caching map with a maximum capacity equal to thecapacity
parameter. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
protected boolean
removeEldestEntry
(Map.Entry<String, SoftReference<T>> eldest) Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
Methods inherited from class java.util.AbstractMap
toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
Constructor Details
-
CachingMap
public CachingMap(int capacity) Creates a caching map with a maximum capacity equal to thecapacity
parameter.- Parameters:
capacity
- the maximum capacity; ifcapacity < 1
then this map will always remove the latest added element
-
-
Method Details
-
removeEldestEntry
- Overrides:
removeEldestEntry
in classLinkedHashMap<String,
SoftReference<T>>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceMap<String,
SoftReference<T>> - Overrides:
hashCode
in classAbstractMap<String,
SoftReference<T>>
-
equals
- Specified by:
equals
in interfaceMap<String,
SoftReference<T>> - Overrides:
equals
in classAbstractMap<String,
SoftReference<T>>
-