Table of Contents

Interface ICacheable

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

Declares that a message's result may be cached, and describes how.

public interface ICacheable
Extension Methods

Remarks

None of these members depends on the message's result type, so they live here rather than on ICacheable<T>. That is what lets the caching middleware recognise a cacheable message with a type test and call these directly. While they sat on the generic interface the middleware could not name a closed type to match against, so it resolved them by walking the runtime type's interfaces and invoking each member through reflection — on the cache hot path, and unanalysable by the trimmer.

Implement ICacheable<T>; it derives from this and carries the result type.

Properties

ExpirationSeconds

Gets how long a cached result stays valid, in seconds.

int ExpirationSeconds { get; }

Property Value

int

Defaults to 60. Zero or less falls back to the configured default expiration.

Methods

CreateCachedResult(object?)

Builds a strongly-typed cache-hit result wrapping value.

IMessageResult? CreateCachedResult(object? value)

Parameters

value object

The deserialized cached value.

Returns

IMessageResult

A message result wrapping value, or null if value is not assignable to this message's declared result type -- the same fail-open signal a cache-hit type mismatch already produces elsewhere.

Remarks

ICacheable<T> overrides this with a default interface method that knows T at its declaration site, so the caching middleware can build the typed result directly through the interface instead of resolving IDispatchAction<TResponse> and invoking a constructor by reflection. The base implementation returns null because the non-generic interface has no type to construct.

GetCacheKey()

Builds the key this message's result is cached under.

string GetCacheKey()

Returns

string

The cache key.

GetCacheTags()

Gets the tags the cached result is filed under, so it can be invalidated by tag.

string[]? GetCacheTags()

Returns

string[]

The tags, or null for none.

ShouldCache(object?)

Decides whether a particular result is worth caching.

bool ShouldCache(object? result)

Parameters

result object

The result the handler produced.

Returns

bool

true to cache it; otherwise false.