Polly缓存-InMemory

时间:2018-10-19 17:05:20

标签: polly

我一直在寻找一个很好的示例,该示例描述了使用内存缓存选项在.net core 2.1中实现Polly缓存。我已经到了启动时配置缓存设置的地步。

   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;
                });

0 个答案:

没有答案