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
    Modifier and Type
    Interface
    Description
    static final record 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<@Nullable Long>
    emptyMetadata(int size)
     
    default boolean
    Returns true if no keys are currently tracked.
    void
    onAccess(K key)
    Called when an existing key is accessed (e.g., via get() or containsKey()).
    void
    onInsert(K key)
    Called when a new or updated key is inserted.
    void
    onRemove(K key)
    Called when a key is removed from the map.
    void
    Replace strategy-specific eviction metadata from a snapshot.
    @Nullable K
    Selects a key to evict based on the eviction strategy.
    int
    Returns the number of distinct keys currently tracked.
    Capture strategy-specific eviction metadata in deterministic victim order.
  • Method Details

    • emptyMetadata

      static List<@Nullable Long> emptyMetadata(int size)
    • onAccess

      void onAccess(K key)
      Called when an existing key is accessed (e.g., via get() or containsKey()). Updates tracking information to reflect the access.
    • onInsert

      void onInsert(K key)
      Called when a new or updated key is inserted. Initializes or resets tracking information for that key.
    • onRemove

      void onRemove(K key)
      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

      Capture strategy-specific eviction metadata in deterministic victim order.
    • restoreState

      void restoreState(EvictionStrategy.EvictionState<K> state)
      Replace strategy-specific eviction metadata from a snapshot.
    • isEmpty

      default boolean isEmpty()
      Returns true if no keys are currently tracked.