public final class LruMemoryStore.SpoolingLinkedHashMap
extends java.util.LinkedHashMap
removeEldestEntry(java.util.Map.Entry)
to persist cache entries to the auxiliary cache before they are removed.
This implementation also provides LRU by access order.Modifier and Type | Field and Description |
---|---|
private static float |
GROWTH_FACTOR |
private static int |
INITIAL_CAPACITY |
private java.util.Set<java.lang.Object> |
pinnedKeys |
Constructor and Description |
---|
SpoolingLinkedHashMap()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isPinned(java.lang.Object key)
Check if the key is pinned
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value) |
protected boolean |
removeEldestEntry(java.util.Map.Entry eldest)
Returns true if this map should remove its eldest entry.
|
private boolean |
removeLeastRecentlyUsedElement(Element element)
Relies on being called from a synchronized method
|
void |
setPinning(java.lang.Object key,
boolean pinned)
Mark the key as pinned or not
|
void |
unpinAll()
unpin all pinned keys
|
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, size
private static final int INITIAL_CAPACITY
private static final float GROWTH_FACTOR
private final java.util.Set<java.lang.Object> pinnedKeys
public SpoolingLinkedHashMap()
public void setPinning(java.lang.Object key, boolean pinned)
key
- the key to be pinned or notpinned
- true if the key should be pinned, false otherwisepublic boolean isPinned(java.lang.Object key)
key
- the key to be checkedpublic void unpinAll()
protected final boolean removeEldestEntry(java.util.Map.Entry eldest)
removeEldestEntry
in class java.util.LinkedHashMap
eldest
- The least recently inserted entry in the map, or if
this is an access-ordered map, the least recently accessed
entry. This is the entry that will be removed it this
method returns true. If the map was empty prior
to the put or putAll invocation resulting
in this invocation, this will be the entry that was just
inserted; in other words, if the map contains a single
entry, the eldest entry is also the newest.public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.HashMap
private boolean removeLeastRecentlyUsedElement(Element element) throws CacheException
element
- CacheException