K
- the type of keys maintained by this cacheV
- the type of values maintained by this cache@API(status=INTERNAL,
since="1.6")
public class LruCache<K,V>
extends java.util.LinkedHashMap<K,V>
This class is not thread-safe.
Modifier and Type | Field and Description |
---|---|
private int |
maxSize |
private static long |
serialVersionUID |
Constructor and Description |
---|
LruCache(int maxSize)
Create a new LRU cache that maintains at most the supplied number of
entries.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
removeEldestEntry(java.util.Map.Entry<K,V> eldest) |
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
private static final long serialVersionUID
private final int maxSize
public LruCache(int maxSize)
For optimal use of the internal data structures, you should pick a
number that's one below a power of two since this is based on a
HashMap
and the eldest entry will be evicted after
adding the entry that increases the size to be above
maxSize
.