How to use in-memory caching in ASP.NET Core

Take advantage of in-memory caching in ASP.NET Core to improve the performance and scalability of your application

How to use in-memory caching in ASP.NET Core
Thinkstock

ASP.NET Core is a lean and modular framework that can be used to build high-performance, modern web applications on Windows, Linux, or MacOS. Unlike legacy ASP.NET, ASP.NET Core doesn’t have a Cache object. However, ASP.NET Core provides support for several different types of caching including in-memory caching, distributed caching, and response caching.

In this article, we’ll look at how you can boost your ASP.NET Core application’s performance and scalability by storing infrequently changing data in the in-memory cache. As always, I will include code examples to illustrate the concepts discussed. 

How to enable in-memory caching in ASP.NET Core

The in-memory cache in ASP.NET Core is a service that you can incorporate into your application using dependency injection. Once you have created an ASP.NET Core project in Visual Studio, you can enable the in-memory cache in the ConfigureServices method in the Startup class as shown in the code snippet below.

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddMemoryCache();
}

To continue reading this article register now

How to choose a low-code development platform