Wednesday, 14 December 2011

How To Apply "OutputCacheExtensibility"

WHAT IS CACHING: “Caching”, a process of taking data or information and persisting a copy of it in memory for a specific time period for immediate access to requesting program calls.
TYPES OF CACHING: Caching can be of following types-
  •           Page Level Caching: This caching works at the page level. It is the easiest means for caching pages.
  •           Fragment Caching: This caching works for the portions of pages.
  •           Data Caching: This caching allows developers to programmatically retain arbitrary data across requests.
LIMITATION IN ASP.NET 3.5:    In the previous versions there were limitations on the feasible extent of caching, because cached content always had to be stored in-memory. 
IMPROVEMENTS IN ASP.NET 4.0: Now with the help of “output-cache providers‟ cache contents can store at any persistence mechanism such as databases, disks, cloud storage and distributed cache engines.

  •           When there is memory crisis, the cache data was truncated first for memory release.
  •           Object cache API that exists in system.web was designed and designed only for Web Applications. In other type of applications like console application or Windows Form Application, this caching might not work properly.
For applying Caching you have to add the below line at the top of the .aspx file of each page-
<%@ OutputCache Duration=“300" VaryByParam=“ID"  ProviderName=“DiskCache %>
Like this:

Now you have to register the output cache provider under system.web in the web.config file of your application as shown below:

Now save the pages and enjoy the magic of “OutputCacheExtensibility”.
  •           By applying output cache you are now able to write more efficient cache mechanism for your Web Application that will improve the responsiveness of your web application.
  •           Now you can store the cache contents to any persistent mechanism such as database, disks, cloud storage, and distributed cache engines.

No comments:

Post a Comment