K
- The type of the map key.V
- The type of the map value.Serializable
, Cloneable
, Map<K,V>
public class LRUCache<K,V> extends LinkedHashMap<K,V>
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
Modifier and Type | Field | Description |
---|---|---|
protected int |
maxCacheSize |
Constructor | Description |
---|---|
LRUCache() |
Default constructor for an LRU Cache The default capacity is 10000
|
LRUCache(int maximumCacheSize) |
Constructs a LRUCache with a maximum capacity
|
LRUCache(int initialCapacity,
int maximumCacheSize,
float loadFactor,
boolean accessOrder) |
Constructs an empty LRUCache instance with the specified
initial capacity, maximumCacheSize,load factor and ordering mode.
|
Modifier and Type | Method | Description |
---|---|---|
int |
getMaxCacheSize() |
|
protected void |
onCacheEviction(Map.Entry<K,V> eldest) |
Event point used by subclasses to perform some cleanup action when an
element is evicted from the cache.
|
protected boolean |
removeEldestEntry(Map.Entry<K,V> eldest) |
|
void |
setMaxCacheSize(int maxCacheSize) |
equals, hashCode, toString
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
public LRUCache()
public LRUCache(int maximumCacheSize)
maximumCacheSize
- The maximum number of elements to keep in the Cache before eviction starts.public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder)
initialCapacity
- The initial capacity.maximumCacheSize
- The maximum number of elements to keep in the Cache before eviction starts.loadFactor
- The load factor to configure on the underlying map.accessOrder
- the ordering mode - true for access-order,
false for insertion-order.IllegalArgumentException
- if the initial capacity is negative or
the load factor is non-positive.public int getMaxCacheSize()
public void setMaxCacheSize(int maxCacheSize)
maxCacheSize
- The maxCacheSize to set.protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
removeEldestEntry
in class LinkedHashMap<K,V>
Copyright © 2017–2018. All rights reserved.