Interface EvictionStrategy<K>
- Type Parameters:
K- the type of keys in the map
- All Known Implementing Classes:
FifoEvictionStrategy, LfuEvictionStrategy, LruEvictionStrategy, RandomEvictionStrategy
public sealed interface EvictionStrategy<K>
permits LruEvictionStrategy<K>, LfuEvictionStrategy<K>, FifoEvictionStrategy<K>, RandomEvictionStrategy<K> (not exhaustive)
Strategy interface for eviction policies in DistributedMap.
Implementations track key access patterns (recency, frequency, or random) and provide a victim selection algorithm when the map reaches its size limit.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionemptyMetadata(int size) default booleanisEmpty()Returns true if no keys are currently tracked.voidCalled 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.
-
Method Details
-
emptyMetadata
-
onAccess
Called when an existing key is accessed (e.g., via get() or containsKey()). Updates tracking information to reflect the access. -
onInsert
Called when a new or updated key is inserted. Initializes or resets tracking information for that key. -
onRemove
Called when a key is removed from the map. Cleans up any tracking information associated with the key. -
selectVictim
@Nullable K selectVictim()Selects a key to evict based on the eviction strategy. Returns null if no suitable victim can be found (e.g., empty map). -
size
int size()Returns the number of distinct keys currently tracked. Used for statistics and diagnostics. -
snapshotState
EvictionStrategy.EvictionState<K> snapshotState()Capture strategy-specific eviction metadata in deterministic victim order. -
restoreState
Replace strategy-specific eviction metadata from a snapshot. -
isEmpty
default boolean isEmpty()Returns true if no keys are currently tracked.
-