How To Do Caching In Asp.Net MVC


Today, I want to talk about how to do caching in Asp.Net MVC projects. Microsoft Asp.Net MVC framework has builtin support for caching mechanism. We will use this  with annotations OutputCache to our controllers.

In this code, Duration means response cache time in seconds.  If you use the Location property of output cache, you can control the output cache location. For instance, if you want some personal information is cached, then  I recommend you to cache it on the client. If your output data is private/confidential, you shall not to store it in the cache.

If you want to inform proxy servers use the NoStore property. And they should not store a permanent copy of the cached content by setting Cache-Control: no-store within the request header.

Output caching allows you to store the output of a particular controller action in memory. Then the engine can respond to future requests for the same action just by giving back the cached result. You should have a look at my another post about Logging In Asp.Net MVC

If you have question do not forget to write from the chat button next to it or from the comment

You may also like...

2 Responses

  1. March 11, 2019

    […] You should have a look at my another post about Caching In Asp.Net MVC […]

  2. May 2, 2022

    […] You may like to see one of my post about caching. How To Do Caching In Asp.Net MVC […]

Leave a Reply

Your email address will not be published. Required fields are marked *