Table of Contents

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

builder IDispatchBuilder

The dispatch builder.

configure Action<CacheOptions>

Optional action to configure cache options.

Returns

IDispatchBuilder

The builder for fluent chaining.

Examples

services.AddDispatch(dispatch =>
{
    dispatch.UseCaching();
});

Exceptions

ArgumentNullException

Thrown when builder is 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

builder IDispatchBuilder

The IDispatchBuilder to configure.

configuration IConfiguration

The 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

builder IDispatchBuilder

The IDispatchBuilder to configure.

configure Action<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

builder IDispatchBuilder

The IDispatchBuilder to configure.

policy Func<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

builder IDispatchBuilder

The IDispatchBuilder to configure.

shouldCache Func<TMessage, object, bool>

Delegate that decides whether a result should be cached.

Returns

IDispatchBuilder

The configured IDispatchBuilder.

Type Parameters

TMessage

The 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

builder IDispatchBuilder

The IDispatchBuilder to configure.

Returns

IDispatchBuilder

The configured IDispatchBuilder.

Type Parameters

TMessage

The message type.

TPolicy

The policy implementation.