pub struct ToolResultCache { /* private fields */ }Expand description
In-memory, session-scoped cache for tool results.
§Design
ttl = Nonemeans entries never expire (useful for batch/scripted sessions).ttl = Some(d)means entries expire after durationd.- Lazy eviction: expired entries are removed on
get(). - No max-size cap: a session cache is bounded by session duration and interaction rate.
- Not
Send + Syncby design — accessed only from the agent’s single-threaded loop.
Implementations§
Source§impl ToolResultCache
impl ToolResultCache
Sourcepub fn new(enabled: bool, ttl: Option<Duration>) -> Self
pub fn new(enabled: bool, ttl: Option<Duration>) -> Self
Create a new cache with the given TTL and enabled state.
ttl = None means entries never expire.
Sourcepub fn get(&mut self, key: &CacheKey) -> Option<ToolOutput>
pub fn get(&mut self, key: &CacheKey) -> Option<ToolOutput>
Look up a cached result. Returns None on miss or if expired.
Expired entries are removed lazily on access.
Sourcepub fn put(&mut self, key: CacheKey, output: ToolOutput)
pub fn put(&mut self, key: CacheKey, output: ToolOutput)
Store a tool result in the cache.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of entries currently in the cache (including potentially expired ones).
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether the cache is enabled.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToolResultCache
impl RefUnwindSafe for ToolResultCache
impl Send for ToolResultCache
impl Sync for ToolResultCache
impl Unpin for ToolResultCache
impl UnsafeUnpin for ToolResultCache
impl UnwindSafe for ToolResultCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more