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 LinkedHashMap<K,V>
This class is not thread-safe.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
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(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
equals, hashCode, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
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
.
protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
removeEldestEntry
in class LinkedHashMap<K,V>
Copyright © 2020. All rights reserved.