Class LruEvictionStrategy
java.lang.Object
org.springframework.ai.tool.toolsearch.eviction.LruEvictionStrategy
- All Implemented Interfaces:
ToolIndexEvictionStrategy
A
ToolIndexEvictionStrategy that evicts the least-recently-used session when
the number of concurrently active sessions exceeds a configured maximum.
Access order is updated on every onAccess(java.lang.String) call, so a session that receives a
new request is moved to the most-recently-used position and will not be a candidate for
eviction until all other sessions have been accessed.
This strategy is suitable for remote vector databases and API-based embedding models, where the number of sessions whose embeddings are retained in the store must be bounded.
- 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
-
LruEvictionStrategy
public LruEvictionStrategy(int maxSessions) Creates a new LruEvictionStrategy.- Parameters:
maxSessions- maximum number of sessions whose indexes are retained; 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
-