Class CompositeEvictionStrategy

java.lang.Object
org.springframework.ai.tool.toolsearch.eviction.CompositeEvictionStrategy
All Implemented Interfaces:
ToolIndexEvictionStrategy

public final class CompositeEvictionStrategy extends Object implements ToolIndexEvictionStrategy
A ToolIndexEvictionStrategy that delegates to multiple strategies and unions their eviction decisions.

All delegates receive every onAccess(java.lang.String) and onRemoved(java.lang.String) call. A session is evicted if any delegate requests its eviction. Typical usage is to combine LRU capacity bounding with TTL-based idle cleanup.

Since:
2.0.0
Author:
Christian Tzolov
  • Constructor Details

    • CompositeEvictionStrategy

      public CompositeEvictionStrategy(ToolIndexEvictionStrategy... strategies)
      Creates a composite strategy from the given delegates.
      Parameters:
      strategies - one or more strategies to combine; must not be empty
  • Method Details

    • onAccess

      public Set<String> onAccess(String sessionId)
      Description copied from interface: ToolIndexEvictionStrategy
      Called each time a session is accessed at the start of request processing.

      Implementations should update their internal tracking state for sessionId and return the set of session IDs whose tool indexes must now be cleared. The returned set must never include the currently-accessed sessionId.

      Specified by:
      onAccess in interface ToolIndexEvictionStrategy
      Parameters:
      sessionId - the session being accessed
      Returns:
      session IDs to evict; never null, may be empty
    • onRemoved

      public void onRemoved(String sessionId)
      Description copied from interface: ToolIndexEvictionStrategy
      Called after a session's tool index has been cleared — either because this strategy returned it from ToolIndexEvictionStrategy.onAccess(java.lang.String), or because of an explicit eviction request.

      Implementations should remove any internal tracking state for the evicted session.

      Specified by:
      onRemoved in interface ToolIndexEvictionStrategy
      Parameters:
      sessionId - the session that was evicted