Implementing a distributed cache

As we mentioned previously, ASP.NET Core allows us to implement distributed caching. In this section, we will learn how to use Redis as a form of cache storage. It is possible to extend the behavior of the caching mechanism of ASP.NET Core by adding and executing the following CLI instruction in the Catalog.API project:

 dotnet add package Microsoft.Extensions.Caching.Redis

By doing this, we can connect the Redis server and use it by adding the following extension method to the Startup class:

public class Startup    {        ...        public void ConfigureServices(IServiceCollection services)        {            ...            services                .AddDistributedRedisCache(                       options => { options.Configuration =                        "catalog_cache:6380";                });               ...        }    }}

Microsoft provides ...

Get Hands-On RESTful Web Services with ASP.NET Core 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.