Package de.aristaflow.adept2.util
Class CleanableCache<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
org.apache.commons.collections4.map.AbstractHashedMap<K,V>
org.apache.commons.collections4.map.AbstractLinkedMap<K,V>
org.apache.commons.collections4.map.LRUMap<K,V>
de.aristaflow.adept2.util.CleanableCache<K,V>
- Type Parameters:
K- The type of the index of the cache.V- The type of the objects of the cache.
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,,V> org.apache.commons.collections4.BoundedMap<K,,V> org.apache.commons.collections4.Get<K,,V> org.apache.commons.collections4.IterableGet<K,,V> org.apache.commons.collections4.IterableMap<K,,V> org.apache.commons.collections4.OrderedMap<K,,V> org.apache.commons.collections4.Put<K,V>
public class CleanableCache<K,V>
extends org.apache.commons.collections4.map.LRUMap<K,V>
Cache implementation with cleanup logic applied when removing an entry due to the cache becoming
too big. Cleanup is performed while adding the new entry.
Note that this class uses lambda expressions and therefore its serialisation will be refused.
Note that this class uses lambda expressions and therefore its serialisation will be refused.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.collections4.map.AbstractLinkedMap
org.apache.commons.collections4.map.AbstractLinkedMap.EntrySetIterator<K extends Object,V extends Object>, org.apache.commons.collections4.map.AbstractLinkedMap.KeySetIterator<K extends Object>, org.apache.commons.collections4.map.AbstractLinkedMap.LinkEntry<K extends Object, V extends Object>, org.apache.commons.collections4.map.AbstractLinkedMap.LinkIterator<K extends Object, V extends Object>, org.apache.commons.collections4.map.AbstractLinkedMap.LinkMapIterator<K extends Object, V extends Object>, org.apache.commons.collections4.map.AbstractLinkedMap.ValuesIterator<V extends Object> Nested classes/interfaces inherited from class org.apache.commons.collections4.map.AbstractHashedMap
org.apache.commons.collections4.map.AbstractHashedMap.EntrySet<K extends Object,V extends Object>, org.apache.commons.collections4.map.AbstractHashedMap.HashEntry<K extends Object, V extends Object>, org.apache.commons.collections4.map.AbstractHashedMap.HashIterator<K extends Object, V extends Object>, org.apache.commons.collections4.map.AbstractHashedMap.HashMapIterator<K extends Object, V extends Object>, org.apache.commons.collections4.map.AbstractHashedMap.KeySet<K extends Object>, org.apache.commons.collections4.map.AbstractHashedMap.Values<V extends Object> Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
FieldsModifier and TypeFieldDescriptionThe logic executed when (before) moving an entry to the most recent position.The logic executed when (before) removing the least recently used entry.Fields inherited from class org.apache.commons.collections4.map.LRUMap
DEFAULT_MAX_SIZEFields inherited from class org.apache.commons.collections4.map.AbstractHashedMap
DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_THRESHOLD, GETKEY_INVALID, GETVALUE_INVALID, MAXIMUM_CAPACITY, NO_NEXT_ENTRY, NO_PREVIOUS_ENTRY, NULL, REMOVE_INVALID, SETVALUE_INVALID -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class org.apache.commons.collections4.map.LRUMap
addMapping, clone, doReadObject, doWriteObject, get, get, isFull, isScanUntilRemovable, maxSize, reuseMapping, updateEntryMethods inherited from class org.apache.commons.collections4.map.AbstractLinkedMap
addEntry, clear, containsValue, createEntry, createEntrySetIterator, createKeySetIterator, createValuesIterator, entryAfter, entryBefore, firstKey, getEntry, getEntry, init, lastKey, mapIterator, nextKey, previousKey, removeEntryMethods inherited from class org.apache.commons.collections4.map.AbstractHashedMap
calculateNewCapacity, calculateThreshold, checkCapacity, containsKey, convertKey, destroyEntry, ensureCapacity, entryHashCode, entryKey, entryNext, entrySet, entryValue, equals, hash, hashCode, hashIndex, isEmpty, isEqualKey, isEqualValue, keySet, put, putAll, remove, removeMapping, reuseEntry, size, toString, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.collections4.Get
containsKey, containsValue, entrySet, isEmpty, keySet, remove, size, valuesMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from interface org.apache.commons.collections4.Put
clear, put, putAll
-
Field Details
-
move
The logic executed when (before) moving an entry to the most recent position. -
remove
The logic executed when (before) removing the least recently used entry.
-
-
Constructor Details
-
CleanableCache
public CleanableCache(int size, Consumer<Map.Entry<? extends K, ? extends V>> move, Consumer<Map.Entry<? extends K, ? extends V>> remove) Constructor, taking the size of the cache and logic for moving and removing entries. When the size is reached, every newAbstractHashedMap.put(Object, Object)will remove the least recently used entry and calling the designated remove logic for it.- Parameters:
size- The maximum size of the cache.move- The code executed when (before) moving an entry to the most recent position. This may benull.remove- The code executed when (before) removing the least recently used object. This may benull.
-
-
Method Details
-
moveToMRU
-
removeLRU
-