In-memory caching in ASP.NET Core
Using in-memory caching allows developers to store data in the server's resources, specifically in memory. Hence, it helps developers improve performance by removing unnecessary HTTP requests to external data sources.
Implementing in-memory caching in ASP.NET Core is dead simple. However, we will not be applying this in our application. We will opt for a more scalable way of caching, that is, distributed caching. We will just look at the parts of how to implement in-memory caching so you'll have an idea.
Enabling in-memory caching in ASP.NET Core
I repeat, we're not going to apply the code from this section to our application. Anyway, you can enable in-memory caching in ConfigureServices
of Startup.cs
:
public void ConfigureServices(IServiceCollection services) { … services.AddMemoryCache(); }
The extension
method adds a non-distributed in-memory implementation in .NET. You can start using...