Polly Cache - InMemory

僤鯓⒐⒋嵵緔 提交于 2020-01-06 05:23:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!