问题
I was looking for a good example which describes implementing Polly caching in .net core 2.1 using the memory cache option. I got to a point configuring the cache settings on startup.
services.AddSingleton<Polly.Registry.IPolicyRegistry<string>, Polly.Registry.PolicyRegistry>((serviceProvider) =>
{
PolicyRegistry registry = new PolicyRegistry();
registry.Add("myCachePolicy", Policy.CacheAsync<HttpResponseMessage>(serviceProvider.GetRequiredService<IAsyncCacheProvider>().AsyncFor<HttpResponseMessage>(), TimeSpan.FromMinutes(5)));
return registry;
});
来源:https://stackoverflow.com/questions/52896987/polly-cache-inmemory