How to use response caching middleware in ASP.Net Core

Take advantage of response caching in ASP.Net Core to improve your application’s performance by reducing the load on the web server

Microsoft's ASP.Net Core has already become a popular way to build high-performance, modern web applications that can run on Windows, Linux, or MacOS. One way it supports high performance of course is caching. Although ASP.Net Core doesn’t have an in-built Cache object, it provides support for several different types of caching including in-memory caching, distributed caching, and response caching.

In previous articles I discussed how to use in-memory caching in ASP.Net Core and how to implement a distributed cache in ASP.Net Core. In this post, I will explain response caching and its benefits and then examine how we can work with the response caching middleware provided in ASP.Net Core.

Response caching explained

Response caching refers to the ability to cache web server responses using cache-related headers in the HTTP response objects. Such headers are used to specify how to cache the responses for either all requests or a few selected requests. Note that unlike output caching, response caching in ASP.Net Core doesn’t cache the responses in the memory of the web server.

Response caching in ASP.Net Core is actually a better and extensible form of output caching. It is used to inform the web browser to cache content by specifying cache-related headers on HTTP responses. This can significantly reduce the number of requests a client makes to the web server, and significantly reduce latency, as subsequent requests can be served from the client’s cache. It should be noted that response caching uses memory to cache the data by default, but you can even configure custom storage providers if need be.

To continue reading this article register now

How to choose a low-code development platform