Caching platforms
.NET 5 supports multiple caching platforms. A few of the commonly used cache platforms are as follows:
- In-memory cache: In this, the cache data is stored inside the process memory. For example, if the application is hosted on IIS, the in-memory cache will consume memory from
w3wp.exe
. - Distributed cache: Data is stored across multiple servers. The data stores that can be integrated with .NET 5 applications are SQL Server, Redis, and NCache.
In-memory cache
To configure memory caching, after creating a new ASP.NET Core 5 MVC/Web API application, or for an existing ASP.NET Core 5 MVC/Web API application, the following code changes are required:
- Add
services.AddMemoryCache()
to theConfigureServices
method ofStartup.cs
. This extension method is part ofMicrosoft.Extensions.DependencyInjection
(install this NuGet package if it's missing) and maps theIMemoryCache
interface to theMemoryCache
class. - The
MemoryCache
class is a built...