Wednesday, February 6, 2013

ASP.NET Caching Complete Reference

One of the core concepts in web development is caching. Understanding why we need caching is important before digging into them.

Caching helps you to reduce traffic to web server by storing some of the 'data' website requires by storing it in some form of memory, than web server serving consequent requests for the same website from that client. This will reduce the web server from redoing everything for each and every request thereby improving the performance.

Caching can be roughly divided into
  • Output caching
  • Application state
  • Cache class
  • Static member variables

Output caching


Output caching has been available since first version of ASP.NET and is also available in ASP.NET MVC as an attribute. 

In ASP.NET you can add a outputcache directive for aspx page. (see example) then for the specified duration of the output cache duration setting the page will be cached.

In MVC you can decorate a action or a whole controller with outputCache attribute. (asp.net). 

Above what we have done is application output caching. There's another concept called proxy output caching. (Article includes good practical example of the usage)

Output Caching is extensible. You can use custom output cache providers. Usually these Custom providers derives from OutputCacheProvider type. You can do the required configurations in Web.config.

Application state 

You can store application level variables Application property of HttpContext. (link)

Cache class

Use cache class to to cache data in a ASP.NET Web application (for other types of applications you can use Memory Cache) sources: Object cache, Object caching 

Static Member variables

Use Static members to store application level attributes which do not change

Powered by Blogger.


Software Architect at Surge Global/ Certified Scrum Master

Experienced in Product Design, Software Engineering, Team management and Practicing Agile methodologies.

Search This Blog

Facebook