Class RedbToolResultCache

Assembly: redb.Route.Llm.dll

REDB-backed . Cache entries are keyed on the
caller-supplied content hash stored in _objects.value_string (partial
index on PostgreSQL/SQLite; MSSQL cannot index NVARCHAR(MAX), lookups there
scan the scheme's rows). The key also rides in _objects._value_unique,
whose per-scheme unique index makes concurrent writers of one key converge
on a single row. TTL is honoured lazily — entries past expiry are dropped on
read.

Distinct from : idempotency answers "have I already run
this tool call (by tool_use_id)?", while this store answers "do I already have an output for
this exact input?". The engine consults this store for ToolCachingPolicy.Persist tools,
after approval and before the idempotency reservation.


The store does not own an instance — each call
resolves one through IRouteContext.GetRedbService(name, exchange),
which honours the per-exchange scope cache. The redb name is read from
exchange.Properties[LlmKeys.RedbName] (set by the LLM endpoint URI),
falling back to the constructor-supplied default name and then to the host's
default unnamed instance.

public sealed class RedbToolResultCache : IToolCacheStore

Inheritance

Object→RedbToolResultCache

Implements

Methods

ClearAsync(IExchange?, CancellationToken)

Drops every entry — used by tests.

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

GetAsync(string, IExchange?, CancellationToken)

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

public 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.

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

Constructors

RedbToolResultCache(IRouteContext, string?)

Creates the store. Scheme is synced by the host's redb.InitializeAsync().