Interface IToolCacheStore

Assembly: redb.Route.Llm.dll

Caches deterministic / read-only tool outputs by a content-hash key so repeated calls can skip
the underlying work: inside one run for ToolCachingPolicy.Memoize (served in process,
never through this store) and across runs for ToolCachingPolicy.Persist.

The agent loop consults this store for Persist tools, after approval and before the
idempotency store: a hit means "this exact input already produced this output", which is cheaper
than asking "was this tool_use already executed?", and it is reported to observers as a skipped
invocation with SkipReason = "cache_hit". Only read-only tools may declare a caching
policy — a cached entry suppresses the side effect it stands for, so the route build rejects
Caching != None on a mutating tool.


An output the redaction filter changed is never stored: persisting the raw body would keep
redaction-bypassing content in the store, and persisting the redacted body would hand the model
different data on a hit than on a miss.


The optional exchange parameter on every method carries the route
pipeline's current exchange; REDB-backed implementations resolve a
per-exchange through
IRouteContext.GetRedbService(name, exchange). In-memory
implementations ignore it.
Without an exchange a redb-backed implementation opens a redb scope of its own for the call. That scope joins an
ambient (a , a
route's .Transacted()) as every redb connection does, but not a transaction begun on the context's shared
IRedbService (ExecuteAtomicAsync, BeginTransaction), which it does not see: pass the exchange,
or use a TransactionScope, when the call must commit or roll back with that work. In-memory implementations
take part in no transaction.


A store does not report metrics. Hit/miss counters belong to the agent loop, which is the
only layer that sees both this store and the run-scoped memo; a store that counted as well would
count every persisted read twice.

public interface IToolCacheStore

Methods

ClearAsync(IExchange?, CancellationToken)

Drops every entry — used by tests.

ValueTask ClearAsync(IExchange? exchange = null, CancellationToken ct = default)

GetAsync(string, IExchange?, CancellationToken)

Returns the cached output for cacheKey, or null on a miss.

ValueTask<string?> GetAsync(string cacheKey, IExchange? exchange = null, CancellationToken ct = default)

SetAsync(string, string, TimeSpan?, IExchange?, CancellationToken)

Stores the cached output and (optionally) sets a relative time-to-live.

ValueTask SetAsync(string cacheKey, string outputJson, TimeSpan? ttl = null, IExchange? exchange = null, CancellationToken ct = default)