Class FifoEvictionStrategy<K>
java.lang.Object
com.loomcache.server.datastructures.FifoEvictionStrategy<K>
- Type Parameters:
K- the type of keys being tracked
- All Implemented Interfaces:
EvictionStrategy<K>
FIFO (First In, First Out) eviction strategy.
Evicts entries in insertion order — the oldest-inserted entry is always the first victim, regardless of access patterns. Unlike LRU, accessing a key does not change its position in the eviction queue.
Uses an ArrayDeque for O(1) insertion and eviction, with a
companion HashSet for O(1) membership checks. Both are protected
by a ReentrantLock to ensure atomic updates between the two
data structures, preventing phantom entries.
-
Nested Class Summary
Nested classes/interfaces inherited from interface EvictionStrategy
EvictionStrategy.EvictionState<K> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when an existing key is accessed (e.g., via get() or containsKey()).voidCalled when a new or updated key is inserted.voidCalled when a key is removed from the map.voidReplace strategy-specific eviction metadata from a snapshot.@Nullable KSelects a key to evict based on the eviction strategy.intsize()Returns the number of distinct keys currently tracked.Capture strategy-specific eviction metadata in deterministic victim order.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EvictionStrategy
isEmpty
-
Constructor Details
-
FifoEvictionStrategy
public FifoEvictionStrategy()
-
-
Method Details
-
onAccess
Description copied from interface:EvictionStrategyCalled when an existing key is accessed (e.g., via get() or containsKey()). Updates tracking information to reflect the access.- Specified by:
onAccessin interfaceEvictionStrategy<K>
-
onInsert
Description copied from interface:EvictionStrategyCalled when a new or updated key is inserted. Initializes or resets tracking information for that key.- Specified by:
onInsertin interfaceEvictionStrategy<K>
-
onRemove
Description copied from interface:EvictionStrategyCalled when a key is removed from the map. Cleans up any tracking information associated with the key.- Specified by:
onRemovein interfaceEvictionStrategy<K>
-
selectVictim
Description copied from interface:EvictionStrategySelects a key to evict based on the eviction strategy. Returns null if no suitable victim can be found (e.g., empty map).- Specified by:
selectVictimin interfaceEvictionStrategy<K>
-
size
public int size()Description copied from interface:EvictionStrategyReturns the number of distinct keys currently tracked. Used for statistics and diagnostics.- Specified by:
sizein interfaceEvictionStrategy<K>
-
snapshotState
Description copied from interface:EvictionStrategyCapture strategy-specific eviction metadata in deterministic victim order.- Specified by:
snapshotStatein interfaceEvictionStrategy<K>
-
restoreState
Description copied from interface:EvictionStrategyReplace strategy-specific eviction metadata from a snapshot.- Specified by:
restoreStatein interfaceEvictionStrategy<K>
-