Package org.apache.dubbo.common.utils
Class LRU2Cache<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.apache.dubbo.common.utils.LRU2Cache<K,V>
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,,V> SequencedMap<K,V>
LRU-2
When the data accessed for the first time, add it to history list. If the size of history list reaches max capacity, eliminate the earliest data (first in first out). When the data already exists in the history list, and be accessed for the second time, then it will be put into cache.
TODO, consider replacing with ConcurrentHashMap to improve performance under concurrency- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.util.LinkedHashMap
containsValue, entrySet, forEach, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, valuesMethods inherited from class java.util.HashMap
clone, compute, computeIfPresent, isEmpty, merge, newHashMap, putAll, putIfAbsent, remove, replace, replaceMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from interface java.util.Map
compute, computeIfPresent, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, replace, replaceMethods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
Constructor Details
-
LRU2Cache
public LRU2Cache() -
LRU2Cache
public LRU2Cache(int maxCapacity)
-
-
Method Details
-
containsKey
- Specified by:
containsKeyin interfaceMap<K,V> - Overrides:
containsKeyin classHashMap<K,V>
-
get
-
put
-
computeIfAbsent
- Specified by:
computeIfAbsentin interfaceMap<K,V> - Overrides:
computeIfAbsentin classHashMap<K,V>
-
remove
-
size
public int size() -
clear
public void clear() -
getMaxCapacity
public int getMaxCapacity() -
setMaxCapacity
public void setMaxCapacity(int maxCapacity)
-