April 2018
Intermediate to advanced
300 pages
7h 41m
English
When making a web request or calling a remote service, Polly can be used to cache the response from the remote service and improve the performance of the application's response time. The Polly cache is classified into two caches, known as the in-memory cache and the distributed cache. We will configure the in-memory cache in this section.
First, we need to add another Polly.Caching.MemoryCache package from NuGet. Once this is added, we will modify our Startup class and add the IPolicyRegistry as a member variable:
private IPolicyRegistry<string> _registry;
In the ConfigurationServices method, we will initialize the registry and add it as a singleton object through DI:
_registry = new PolicyRegistry();services.AddSingleton(_registry); ...