java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
com.renomad.minum.utils.LRUCache<K,V>
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
,V> SequencedMap<K,
V>
A simple Least-Recently Used Cache
See LRU
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> Map <K, V> Builds a map that functions as a least-recently used cache.static <K,
V> Map <K, V> getLruCache
(int maxSize) Creates an LRUCache, allowing you to specify the max size.protected boolean
removeEldestEntry
(Map.Entry<K, V> eldest) Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, values
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, size
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
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
Methods inherited from interface java.util.SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
Method Details
-
removeEldestEntry
- Overrides:
removeEldestEntry
in classLinkedHashMap<K,
V>
-
getLruCache
Builds a map that functions as a least-recently used cache. Sets the max size to DEFAULT_MAX_ENTRIES. If you want to specify the max size, use the constructor atgetLruCache(int)
Make sure, when using this, to assign it to a fully-defined type, e.g.Map<String, String> foo = getLruCache()
This is necessary since we provide this as a generic method, and the assignment is what enables Java to determine what types to build. -
getLruCache
Creates an LRUCache, allowing you to specify the max size. Alternately, seegetLruCache()
.
Make sure, when using this, to assign it to a fully-defined type, e.g.Map<String, String> foo = getLruCache(2)
This is necessary since we provide this as a generic method, and the assignment is what enables Java to determine what types to build.
-