pub struct ResultCache { /* private fields */ }Expand description
Manages cached tool results with expiration and disk budgets.
The cache stores large tool outputs on disk and provides agents with
random-access operations (read, grep, head, tail, stats) via
CacheBackend implementations.
Implementations§
Source§impl ResultCache
impl ResultCache
Sourcepub fn new(
base_dir: impl Into<PathBuf>,
config: ResultCacheConfig,
) -> Result<Self, CacheError>
pub fn new( base_dir: impl Into<PathBuf>, config: ResultCacheConfig, ) -> Result<Self, CacheError>
Create a new cache rooted at base_dir.
The directory is created if it doesn’t exist.
§Errors
Returns CacheError::Io if the directory can’t be created.
Sourcepub fn store(
&mut self,
tool_name: &str,
content: &str,
backend_kind: BackendKind,
) -> Result<String, CacheError>
pub fn store( &mut self, tool_name: &str, content: &str, backend_kind: BackendKind, ) -> Result<String, CacheError>
Store a tool result, returning the reference ID.
The backend_kind determines which backend stores the data.
Currently only BackendKind::Text is supported.
§Errors
Returns CacheError::Io if writing to disk fails.
Sourcepub fn get(&self, ref_id: &str) -> Result<&CacheEntry, CacheError>
pub fn get(&self, ref_id: &str) -> Result<&CacheEntry, CacheError>
Get a cache entry by reference ID.
Sourcepub fn execute_op(
&self,
ref_id: &str,
op: CacheOp,
) -> Result<String, CacheError>
pub fn execute_op( &self, ref_id: &str, op: CacheOp, ) -> Result<String, CacheError>
Execute an operation on a cached entry.
Sourcepub fn evict_expired(&mut self) -> usize
pub fn evict_expired(&mut self) -> usize
Remove all expired entries, returning the count removed.
Sourcepub fn total_bytes(&self) -> u64
pub fn total_bytes(&self) -> u64
Total disk bytes across all entries.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &CacheEntry)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &CacheEntry)>
Iterates over all cache entries.
Returns (ref_id, entry) pairs in arbitrary order.
Sourcepub fn preview_lines(&self) -> usize
pub fn preview_lines(&self) -> usize
The configured number of preview lines.