CachingBehavior<TMessage, TResult> class
Namespace: Vitreous.Caching.Behaviors
Assembly: Vitreous.Caching.dll
Pipeline behavior that short-circuits query execution on a cache hit. Only active for messages that implement ICacheableQuery<TResult>; all other messages pass through unchanged.
public sealed class CachingBehavior<TMessage, TResult> : IPipelineBehavior<TMessage, TResult>Type Parameters
Section titled “Type Parameters”TMessage
TResult
Inheritance
Section titled “Inheritance”object ← CachingBehavior<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”Register this as the innermost behavior (closest to the handler) so outer behaviors such as logging and tracing still execute on cache hits. On a hit the handler is never called. On a miss the result is cached only when IsSuccess is true. Cache failures (e.g. Redis unavailable) are logged as warnings and the handler is called as a fallback — the cache is always a performance layer, never a hard dependency.
With [EnableStampedeProtection](/Vitreous/api/vitreous/caching/vitreouscachingoptions/#Vitreous_Caching_VitreousCachingOptions_EnableStampedeProtection) on (the default), concurrent misses for the same key share one handler run. If the caller running the handler is canceled, the others run it themselves.
Constructors
Section titled “Constructors”CachingBehavior(IVitreousCache, ILogger<CachingBehavior<TMessage, TResult>>)
Section titled “ CachingBehavior(IVitreousCache, ILogger<CachingBehavior<TMessage, TResult>>)”public CachingBehavior(IVitreousCache cache, ILogger<CachingBehavior<TMessage, TResult>> logger)Parameters
Section titled “Parameters”cache IVitreousCache
logger ILogger<CachingBehavior<TMessage, TResult>>
CachingBehavior(IVitreousCache, ILogger<CachingBehavior<TMessage, TResult>>, VitreousCachingOptions?)
Section titled “ CachingBehavior(IVitreousCache, ILogger<CachingBehavior<TMessage, TResult>>, VitreousCachingOptions?)”public CachingBehavior(IVitreousCache cache, ILogger<CachingBehavior<TMessage, TResult>> logger, VitreousCachingOptions? options)Parameters
Section titled “Parameters”cache IVitreousCache
logger ILogger<CachingBehavior<TMessage, TResult>>
options VitreousCachingOptions?
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>