Skip to content

Commit 8e43dfe

Browse files
stephentoubjeffhandley
authored andcommitted
Augment UseDistributedCache XML docs (#6256)
1 parent 9667bfe commit 8e43dfe

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Libraries/Microsoft.Extensions.AI/ChatCompletion/DistributedCachingChatClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ namespace Microsoft.Extensions.AI;
1919
/// A delegating chat client that caches the results of response calls, storing them as JSON in an <see cref="IDistributedCache"/>.
2020
/// </summary>
2121
/// <remarks>
22+
/// <para>
23+
/// The <see cref="DistributedCachingChatClient"/> employs JSON serialization as part of storing cached data. It is not guaranteed that
24+
/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>,
25+
/// or any of the other objects in the chat client pipeline will roundtrip through JSON serialization with full fidelity. For example,
26+
/// <see cref="ChatMessage.RawRepresentation"/> will be ignored, and <see cref="object"/> values in <see cref="ChatMessage.AdditionalProperties"/>
27+
/// will deserialize as <see cref="JsonElement"/> rather than as the original type. In general, code using <see cref="DistributedCachingChatClient"/>
28+
/// should only rely on accessing data that can be preserved well enough through JSON serialization and deserialization.
29+
/// </para>
30+
/// <para>
2231
/// The provided implementation of <see cref="IChatClient"/> is thread-safe for concurrent use so long as the employed
2332
/// <see cref="IDistributedCache"/> is similarly thread-safe for concurrent use.
33+
/// </para>
2434
/// </remarks>
2535
public class DistributedCachingChatClient : CachingChatClient
2636
{

src/Libraries/Microsoft.Extensions.AI/ChatCompletion/DistributedCachingChatClientBuilderExtensions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Text.Json;
56
using Microsoft.Extensions.Caching.Distributed;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Shared.Diagnostics;
@@ -23,6 +24,14 @@ public static class DistributedCachingChatClientBuilderExtensions
2324
/// <param name="configure">An optional callback that can be used to configure the <see cref="DistributedCachingChatClient"/> instance.</param>
2425
/// <returns>The <see cref="ChatClientBuilder"/> provided as <paramref name="builder"/>.</returns>
2526
/// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
27+
/// <remarks>
28+
/// The <see cref="DistributedCachingChatClient"/> employs JSON serialization as part of storing the cached data. It is not guaranteed that
29+
/// the object models used by <see cref="ChatMessage"/>, <see cref="ChatOptions"/>, <see cref="ChatResponse"/>, <see cref="ChatResponseUpdate"/>,
30+
/// or any of the other objects in the chat client pipeline will roundtrip through JSON serialization with full fidelity. For example,
31+
/// <see cref="ChatMessage.RawRepresentation"/> will be ignored, and <see cref="object"/> values in <see cref="ChatMessage.AdditionalProperties"/>
32+
/// will deserialize as <see cref="JsonElement"/> rather than as the original type. In general, code using <see cref="DistributedCachingChatClient"/>
33+
/// should only rely on accessing data that can be preserved well enough through JSON serialization and deserialization.
34+
/// </remarks>
2635
public static ChatClientBuilder UseDistributedCache(this ChatClientBuilder builder, IDistributedCache? storage = null, Action<DistributedCachingChatClient>? configure = null)
2736
{
2837
_ = Throw.IfNull(builder);

0 commit comments

Comments
 (0)