How to implement a distributed cache in ASP.Net Core

Take advantage of a distributed cache to improve the performance and scalability of your ASP.Net Core application

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

ASP.Net Core provides support for various types of caching. In addition to in-memory caching and response caching, it provides built-in support for distributed caching. In one of my previous articles here, I discussed in-memory caching in ASP.Net Core. In this article we will examine how we can work with distributed caching in ASP.Net Core. We will discuss both supported implementations, i.e., using Redis as well as SQL Server as the cache stores.

What is a distributed cache

Distributed caches are used to improve the performance and scalability of applications. Typically, a distributed cache is shared by multiple application servers. In a distributed cache, the cached data doesn’t reside in the memory of an individual web server. Rather, this data is stored centrally so that it is available to all of the application’s servers. If any of the servers go down or stop responding, other servers will still be able to retrieve the cached data. Another advantage of a distributed cache is that the cached data survives server restarts. You can add or remove a server without impacting the cache or the cached data.

To take advantage of a distributed cache when working on ASP.NET Core applications, we will use the IDistributedCache interface. We’ll examine how the IDistributedCache interface differs from the IMemoryCache interface in the section that follows.

The IDistributedCache interface

To continue reading this article register now