Skip to content

CacheInvalidationBehavior<TMessage, TResult> class

Namespace: Vitreous.Caching.Behaviors
Assembly: Vitreous.Caching.dll

Pipeline behavior that removes stale cache entries after a successful command. Only active for messages that implement IInvalidatesCache; all other messages pass through unchanged.

public sealed class CacheInvalidationBehavior<TMessage, TResult> : IPipelineBehavior<TMessage, TResult>

TMessage

TResult

object ← CacheInvalidationBehavior<TMessage, TResult>

IPipelineBehavior<TMessage, TResult>

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Cache entries are removed only when the handler returns a successful Result<T>. On failure, no cache state is modified.

[CacheKeys](/Vitreous/api/vitreous/caching/abstractions/iinvalidatescache/#Vitreous_Caching_Abstractions_IInvalidatesCache_CacheKeys) are honoured by all backends. [InvalidatesTags](/Vitreous/api/vitreous/caching/abstractions/iinvalidatescache/#Vitreous_Caching_Abstractions_IInvalidatesCache_InvalidatesTags) are a no-op with the base IDistributedCache backend and require the Vitreous.Caching.Redis package for actual tag-based bulk removal.

Removal failures are logged as warnings and do not affect the command’s result — the cache may temporarily be stale, but the command succeeded.

CacheInvalidationBehavior(IVitreousCache, ILogger<CacheInvalidationBehavior<TMessage, TResult>>)

Section titled “ CacheInvalidationBehavior(IVitreousCache, ILogger<CacheInvalidationBehavior<TMessage, TResult>>)”
public CacheInvalidationBehavior(IVitreousCache cache, ILogger<CacheInvalidationBehavior<TMessage, TResult>> logger)

cache IVitreousCache

logger ILogger<CacheInvalidationBehavior<TMessage, TResult>>

Handle(TMessage, MessageHandlerDelegate<TMessage, TResult>, CancellationToken)

Section titled “ Handle(TMessage, MessageHandlerDelegate<TMessage, TResult>, CancellationToken)”

Executes this behavior step, calling next to continue the pipeline.

public ValueTask<Result<TResult>> Handle(TMessage message, MessageHandlerDelegate<TMessage, TResult> next, CancellationToken ct = default)

message TMessage

next MessageHandlerDelegate<TMessage, TResult>

ct CancellationToken

ValueTask<Result<TResult>>