Table of Contents

Interface ICacheKeyBuilder

Namespace
Excalibur.Dispatch.Caching
Assembly
Excalibur.Dispatch.Caching.dll

Creates cache keys for dispatch requests.

public interface ICacheKeyBuilder
Extension Methods

Methods

CreateKey(IDispatchAction, IMessageContext)

Builds a stable, hash-safe cache key for the given message and context, or null when no cache identity can be derived for the action.

[RequiresDynamicCode("JSON serialization requires dynamic code generation for type inspection and property access")]
[RequiresUnreferencedCode("JSON serialization may reference types not preserved during trimming")]
string? CreateKey(IDispatchAction action, IMessageContext context)

Parameters

action IDispatchAction

The dispatch action to create a key for.

context IMessageContext

The message context.

Returns

string

A stable cache key string, or null when no cache identity can be derived for action — for example the action declares ICacheable<T> but its key cannot be resolved, or the action cannot be serialized. A null result means "do not cache": the caller MUST bypass the cache and invoke the underlying operation. Implementations MUST be infallible for a "cannot derive a key" condition — return null rather than throwing.

CreateKey(string, string?, string?)

Builds the stored cache key for a logical key under a tenant/user identity, applying the same identity folding and hashing transform as CreateKey(IDispatchAction, IMessageContext) — without a live IMessageContext.

string CreateKey(string logicalKey, string? tenantId, string? userId)

Parameters

logicalKey string

The logical cache identity (e.g. the value a cacheable query exposes via GetCacheKey()).

tenantId string

The tenant identity the entry was stored under, or null for the global tenant.

userId string

The user identity the entry was stored under, or null for an anonymous user.

Returns

string

The storage key that a cacheable query would have stored for logicalKey under the given identity. Use this to turn a direct invalidation key into the exact key to remove — a raw logical key can never equal the stored hashed key.

Remarks

This overload performs no serialization and is AOT- and trimming-safe. It is intended for direct-key cache invalidation, where the tenant/user are derived from the invalidating dispatch's context rather than the original cached request.