In ASP.NET Core, response caching middleware allows response caching. It adds cache-related headers to responses. These headers specify how you want client, proxy, and middleware to cache responses.
To use this, we need to include its package using NuGet, as per .NET Core 2.0 latest version relevant packages are pre-installed:
"Microsoft.AspNetCore.ResponseCaching": "2.0.0-preview2-final "
After the package is installed, update the Startup class to add ResponseCaching to a services collection:
public void ConfigureServices(IServiceCollection services) { //Response Caching Middleware // Code removed for brevity services.AddResponseCaching(); services.AddMvc(); }
Also include the ResponseCaching middleware in HTTP pipeline processing:
public void Configure(IApplicationBuilder app, IHostingEnvironment...