Class CachingDispatchBuilderExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Excalibur.Dispatch.Caching.dll
Extension methods for configuring caching on an IDispatchBuilder.
public static class CachingDispatchBuilderExtensions
- Inheritance
-
CachingDispatchBuilderExtensions
- Inherited Members
Methods
UseCaching(IDispatchBuilder, Action<CacheOptions>?)
Adds Dispatch caching (memory, distributed, hybrid) via the builder.
[RequiresUnreferencedCode("Result caching reconstructs a cached value from the type name stored with the entry, which requires types that trimming may remove. An entry whose type can no longer be resolved is discarded and the handler runs again.")]
[RequiresDynamicCode("Result caching deserializes a cached value by its runtime type, which requires runtime code generation. Under ahead-of-time compilation a serialized entry cannot be reconstructed and the handler runs again.")]
public static IDispatchBuilder UseCaching(this IDispatchBuilder builder, Action<CacheOptions>? configure = null)
Parameters
builderIDispatchBuilderThe dispatch builder.
configureAction<CacheOptions>Optional action to configure cache options.
Returns
- IDispatchBuilder
The builder for fluent chaining.
Examples
services.AddDispatch(dispatch =>
{
dispatch.UseCaching();
});
Exceptions
- ArgumentNullException
Thrown when
builderis null.
WithCachingOptions(IDispatchBuilder, IConfiguration)
Binds CacheOptions from configuration. Binding caching options also enables the feature: the caching services and pipeline middleware are registered as part of this call, so the bound options are always honored without a separate UseCaching(IDispatchBuilder, Action<CacheOptions>?) call.
[RequiresUnreferencedCode("Configuration binding may reference types not preserved during trimming. Ensure options types are annotated with DynamicallyAccessedMembers.")]
[RequiresDynamicCode("Configuration binding for CacheOptions requires dynamic code generation for property reflection and value conversion.")]
public static IDispatchBuilder WithCachingOptions(this IDispatchBuilder builder, IConfiguration configuration)
Parameters
builderIDispatchBuilderThe IDispatchBuilder to configure.
configurationIConfigurationThe configuration section to bind.
Returns
- IDispatchBuilder
The configured IDispatchBuilder.
WithCachingOptions(IDispatchBuilder, Action<CacheOptions>)
Configures caching with a custom options delegate. Configuring caching also enables it: the caching services and pipeline middleware are registered as part of this call, so the configured options are always honored without a separate UseCaching(IDispatchBuilder, Action<CacheOptions>?) call. Registration is idempotent and safe to combine with UseCaching(IDispatchBuilder, Action<CacheOptions>?).
[RequiresUnreferencedCode("Result caching reconstructs a cached value from the type name stored with the entry, which requires types that trimming may remove. An entry whose type can no longer be resolved is discarded and the handler runs again.")]
[RequiresDynamicCode("Result caching deserializes a cached value by its runtime type, which requires runtime code generation. Under ahead-of-time compilation a serialized entry cannot be reconstructed and the handler runs again.")]
public static IDispatchBuilder WithCachingOptions(this IDispatchBuilder builder, Action<CacheOptions> configure)
Parameters
builderIDispatchBuilderThe IDispatchBuilder to configure.
configureAction<CacheOptions>Callback used to set CacheOptions.
Returns
- IDispatchBuilder
The configured IDispatchBuilder.
WithResultCachePolicy(IDispatchBuilder, Func<IDispatchMessage, object?, bool>)
Adds a global result cache policy.
public static IDispatchBuilder WithResultCachePolicy(this IDispatchBuilder builder, Func<IDispatchMessage, object?, bool> policy)
Parameters
builderIDispatchBuilderThe IDispatchBuilder to configure.
policyFunc<IDispatchMessage, object, bool>Delegate that decides whether a result should be cached.
Returns
- IDispatchBuilder
The configured IDispatchBuilder.
WithResultCachePolicy<TMessage>(IDispatchBuilder, Func<TMessage, object?, bool>)
Adds a typed result cache policy for TMessage.
public static IDispatchBuilder WithResultCachePolicy<TMessage>(this IDispatchBuilder builder, Func<TMessage, object?, bool> shouldCache) where TMessage : class, IDispatchMessage
Parameters
builderIDispatchBuilderThe IDispatchBuilder to configure.
shouldCacheFunc<TMessage, object, bool>Delegate that decides whether a result should be cached.
Returns
- IDispatchBuilder
The configured IDispatchBuilder.
Type Parameters
TMessageThe message type.
WithResultCachePolicy<TMessage, TPolicy>(IDispatchBuilder)
Registers a custom result cache policy implementation.
public static IDispatchBuilder WithResultCachePolicy<TMessage, TPolicy>(this IDispatchBuilder builder) where TMessage : class, IDispatchMessage where TPolicy : class, IResultCachePolicy<TMessage>
Parameters
builderIDispatchBuilderThe IDispatchBuilder to configure.
Returns
- IDispatchBuilder
The configured IDispatchBuilder.
Type Parameters
TMessageThe message type.
TPolicyThe policy implementation.