Class EfficientLRUMap<K,V>
java.lang.Object
org.broadleafcommerce.common.util.EfficientLRUMap<K,V>
- All Implemented Interfaces:
Map<K,V>
This class provides an LRUMap structure that defaults to a more efficient ConcurrentHashMap if the
size has not yet been reached.
In Broadleaf, there are many instances where an LRUMap could be used to guard against implementations where Map sizes grow in unexpected ways. However, the large majority of cases would fit well within the max bounds of the LRUMap.
This class provides an approach that provides the benefits of a LRUMap for memory protection while allowing concurrent access under normal circumstances.
For the first [n] entries, the underlying implementation will be a ConcurrentHashMap. On the "n+1"th entry, this implementation will switch its underlying implementation to a synchronized LRUMap.
- Author:
- bpolster
-
Nested Class Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()protected ClassbooleanisEmpty()keySet()voidprotected voidWe are clearing the map, so we can switch back to aConcurrentHashMapintsize()protected booleanvalues()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
EfficientLRUMap
public EfficientLRUMap(int maxEntries)
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
switchToLRUMap
protected boolean switchToLRUMap() -
remove
-
putAll
-
clear
public void clear() -
resetInternalMap
protected void resetInternalMap()We are clearing the map, so we can switch back to aConcurrentHashMap -
keySet
-
values
-
entrySet
-
getUnderlyingMapClass
-