Class TtlEvictionStrategy
java.lang.Object
org.springframework.ai.tool.toolsearch.eviction.TtlEvictionStrategy
- All Implemented Interfaces:
ToolIndexEvictionStrategy
A
ToolIndexEvictionStrategy that evicts sessions whose last-access time is
older than a configured time-to-live (TTL).
Expiry is evaluated lazily on each onAccess(java.lang.String) call: all tracked sessions (other
than the one currently being accessed) are checked against the TTL, and any that have
exceeded it are returned for eviction. No background thread is used.
The TTL resets on every access, so a session that continues to receive requests will not be evicted as long as the gap between consecutive requests stays below the TTL.
- Since:
- 2.0.0
- Author:
- Christian Tzolov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCalled each time a session is accessed at the start of request processing.voidCalled after a session's tool index has been cleared — either because this strategy returned it fromToolIndexEvictionStrategy.onAccess(java.lang.String), or because of an explicit eviction request.
-
Constructor Details
-
TtlEvictionStrategy
Creates a new TtlEvictionStrategy.- Parameters:
ttl- maximum idle time before a session's index is evicted; must be positive
-
-
Method Details
-
onAccess
Description copied from interface:ToolIndexEvictionStrategyCalled each time a session is accessed at the start of request processing.Implementations should update their internal tracking state for
sessionIdand return the set of session IDs whose tool indexes must now be cleared. The returned set must never include the currently-accessedsessionId.- Specified by:
onAccessin interfaceToolIndexEvictionStrategy- Parameters:
sessionId- the session being accessed- Returns:
- session IDs to evict; never
null, may be empty
-
onRemoved
Description copied from interface:ToolIndexEvictionStrategyCalled after a session's tool index has been cleared — either because this strategy returned it fromToolIndexEvictionStrategy.onAccess(java.lang.String), or because of an explicit eviction request.Implementations should remove any internal tracking state for the evicted session.
- Specified by:
onRemovedin interfaceToolIndexEvictionStrategy- Parameters:
sessionId- the session that was evicted
-