public class ExpiringMap<K,V> extends LinkedHashMap<K,V>
timeout. on adding elements, old elements may be removed.
useful for in-memory caches. if you define a timeout of -1, the expiration functionality will be switched off.
Note-1: the LinkedHashMap implementation provides an accessOrder (see it's constructors) and an unimplemented
LinkedHashMap.removeEldestEntry(java.util.Map.Entry) - these are not usable for our cache.
Note-2: As the capacity() evaluation is only be accessible through pure-performance reflection, we may use our
timeout variable as shrink()ing frequency.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Constructor and Description |
|---|
ExpiringMap(int initialCapacity,
float loadFactor,
boolean accessOrder,
long timeout)
constructor
|
ExpiringMap(int initialCapacity,
float loadFactor,
long timeout)
constructor
|
ExpiringMap(int initialCapacity,
long timeout)
constructor
|
ExpiringMap(long timeout)
constructor
|
ExpiringMap(Map<? extends K,? extends V> m,
long timeout)
constructor
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
V |
get(Object key) |
protected void |
init(long timeout)
creates the touch-time table
|
V |
put(K key,
V value) |
V |
remove(Object key) |
protected void |
shrink()
does the thing and removes expired objects.
|
containsValue, entrySet, forEach, getOrDefault, keySet, removeEldestEntry, replaceAll, valuesclone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putAll, putIfAbsent, remove, replace, replace, sizeequals, hashCode, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, replace, replace, sizepublic ExpiringMap(long timeout)
timeout - public ExpiringMap(int initialCapacity,
float loadFactor,
boolean accessOrder,
long timeout)
initialCapacity - loadFactor - accessOrder - public ExpiringMap(int initialCapacity,
float loadFactor,
long timeout)
initialCapacity - loadFactor - public ExpiringMap(int initialCapacity,
long timeout)
initialCapacity - public void clear()
protected void shrink()
protected void init(long timeout)
timeout - The timeout to set.Copyright © 2012–2018. All rights reserved.