You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60-2Lines changed: 60 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ var cachePolicy = Policy.CacheAsync<byte[]>(distributedCache.AsAsyncCacheProvide
72
72
73
73
```
74
74
75
-
Configuration via DI in ASPNET Core:
75
+
## Configuration via DI in ASPNET Core:
76
76
77
77
```csharp
78
78
// In this example we choose to pass a whole PolicyRegistry by dependency injection rather than the individual policy, on the assumption the webapp will probably use multiple policies across the app.
@@ -111,7 +111,65 @@ public MyController(IReadOnlyPolicyRegistry<string> policyRegistry)
111
111
}
112
112
```
113
113
114
-
Usage:
114
+
## Automatically serializing more complex type
115
+
116
+
The raw cache provider `Polly.Caching.IDistributedCache` allows you to cache items of type `byte[]` or `string` as those are the native formats supported by [`Microsoft.Extensions.Caching.Distributed.IDistributedCache`](https://docs.microsoft.com/en-gb/dotnet/api/microsoft.extensions.caching.distributed.idistributedcache). However, Polly also allows you to automatically serialize more complex types.
117
+
118
+
The package `Polly.Caching.Serialization.Json` ([github](https://github.com/App-vNext/Polly.Caching.Serialization.Json); [nuget](https://www.nuget.org/packages/Polly.Caching.Serialization.Json)) is a Polly [`ICacheItemSerializer<TResult, string>`](https://github.com/App-vNext/Polly/wiki/Implementing-cache-serializers#using-a-serializer-with-the-polly-cachepolicy) to serialize any type for use with `Polly.Caching.IDistributedCache`.
// Obtain a Newtonsoft.Json.JsonSerializerSettings defining any settings to use for serialization
134
+
// (could alternatively be obtained from a factory by DI)
135
+
varserializerSettings=newJsonSerializerSettings()
136
+
{
137
+
// Any configuration options
138
+
};
139
+
140
+
// Register a Polly cache provider for caching ProductDetails entities, using the IDistributedCache instance and a Polly.Caching.Serialization.Json.JsonSerializer.
141
+
// (ICacheItemSerializer<ProductDetails, string> could alternatively be obtained from a factory by DI)
0 commit comments