DistributedCachingChatClientBuilderExtensions.UseDistributedCache Method

Definition

Adds a DistributedCachingChatClient as the next stage in the pipeline.

public static Microsoft.Extensions.AI.ChatClientBuilder UseDistributedCache(this Microsoft.Extensions.AI.ChatClientBuilder builder, Microsoft.Extensions.Caching.Distributed.IDistributedCache? storage = default, Action<Microsoft.Extensions.AI.DistributedCachingChatClient>? configure = default);
static member UseDistributedCache : Microsoft.Extensions.AI.ChatClientBuilder * Microsoft.Extensions.Caching.Distributed.IDistributedCache * Action<Microsoft.Extensions.AI.DistributedCachingChatClient> -> Microsoft.Extensions.AI.ChatClientBuilder
<Extension()>
Public Function UseDistributedCache (builder As ChatClientBuilder, Optional storage As IDistributedCache = Nothing, Optional configure As Action(Of DistributedCachingChatClient) = Nothing) As ChatClientBuilder

Parameters

storage
IDistributedCache

An optional IDistributedCache instance that will be used as the backing store for the cache. If not supplied, an instance will be resolved from the service provider.

configure
Action<DistributedCachingChatClient>

An optional callback that can be used to configure the DistributedCachingChatClient instance.

Returns

The ChatClientBuilder provided as builder.

Exceptions

builder is null.

Remarks

The DistributedCachingChatClient employs JSON serialization as part of storing the cached data. It is not guaranteed that the object models used by ChatMessage, ChatOptions, ChatResponse, ChatResponseUpdate, or any of the other objects in the chat client pipeline will roundtrip through JSON serialization with full fidelity. For example, RawRepresentation will be ignored, and Object values in AdditionalProperties will deserialize as JsonElement rather than as the original type. In general, code using DistributedCachingChatClient should only rely on accessing data that can be preserved well enough through JSON serialization and deserialization.

Applies to