Skip to content

Commit fae6a05

Browse files
committed
Add doco about .For<>() and .AsyncFor<>()
Add documentation about .For<>() and .AsyncFor<>() extension methods.
1 parent bd19386 commit fae6a05

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class Startup
6969
services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>((serviceProvider) =>
7070
{
7171
PolicyRegistry registry = new PolicyRegistry();
72-
registry.Add("myCachePolicy", Policy.CacheAsync<HttpResponseMessage>(serviceProvider.GetRequiredService<IAsyncCacheProvider>(), TimeSpan.FromMinutes(5)));
72+
registry.Add("myCachePolicy", Policy.CacheAsync<HttpResponseMessage>(serviceProvider.GetRequiredService<IAsyncCacheProvider>().AsyncFor<HttpResponseMessage>(), TimeSpan.FromMinutes(5)));
7373
return registry;
7474
});
7575

@@ -89,6 +89,11 @@ public MyController(IPolicyRegistry<string> policyRegistry)
8989

9090
For many more configuration options and usage examples of the main Polly `CachePolicy`, see the [main Polly readme](https://github.com/App-vNext/Polly#cache) and [deep doco on the Polly wiki](https://github.com/App-vNext/Polly/wiki/Cache).
9191

92+
## Note
93+
94+
`Polly.Caching.Memory.MemoryCacheProvider : ISyncCacheProvider, IAsyncCacheProvider` is non-generic as the underlying `Microsoft.Extensions.Caching.Memory.IMemoryCache` is non-generic. However, when defining a generic Polly cache policy `Policy.Cache/CacheAsync<TResult>(...)`, some overloads require a generic `ISyncCacheProvider<TResult>` or `IAsyncCacheProvider<TResult>`.
95+
96+
In this case, use the extensions methods `MemoryCacheProvider.For<TResult>()` or `MemoryCacheProvider.AsyncFor<TResult>()`, as shown in the ASP.NET Core example above, to obtain a generic `ISyncCacheProvider<TResult>` or `IAsyncCacheProvider<TResult>`.
9297

9398
# Release notes
9499

0 commit comments

Comments
 (0)