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>Type Parameters
Section titled “Type Parameters”TMessage
TResult
Inheritance
Section titled “Inheritance”object ← CacheInvalidationBehavior<TMessage, TResult>
Implements
Section titled “Implements”IPipelineBehavior<TMessage, TResult>
Inherited Members
Section titled “Inherited Members”object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
Section titled “Remarks”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.
Constructors
Section titled “Constructors”CacheInvalidationBehavior(IVitreousCache, ILogger<CacheInvalidationBehavior<TMessage, TResult>>)
Section titled “ CacheInvalidationBehavior(IVitreousCache, ILogger<CacheInvalidationBehavior<TMessage, TResult>>)”public CacheInvalidationBehavior(IVitreousCache cache, ILogger<CacheInvalidationBehavior<TMessage, TResult>> logger)Parameters
Section titled “Parameters”cache IVitreousCache
logger ILogger<CacheInvalidationBehavior<TMessage, TResult>>
Methods
Section titled “Methods”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)Parameters
Section titled “Parameters”message TMessage
next MessageHandlerDelegate<TMessage, TResult>