Improving the performance of your ASP.NET Web application through output caching !!!
Page level Caching is a technique to store output of a request sent to the page, which helps to increase the performance of application. Data can be fetched from previous cache memory instead of processing the request again. Following is the directive you need to add to top of your .aspx page.
Duration:
The time interval( in seconds ) to cache the page again .
VaryByParam: The value of this properties decides whether to cache the page for vary in querystring parameter with same absolute path. To cache the page for different querystring key you have to specify that key as the attribute . For example : If a page has two different “mode” i.e. Add and Edit, then we can specify VaryByParam = “mode” to cache it separately for add and edit.
[There are many properties for this directive also]
Instead of caching the page entirely we can cache portions of a page and can have dynamic region too. One of the new controls introduced with ASP.NET 2.0 was the “Substitution” control. By using this control, we can create pages that participate in output caching but also have regions designated to contain dynamic content that will be updated on every page request.
In the following Example I have created a page with cache duration 30 seconds. I have set a timer which shows real time and another for showing previous cache time which will be refreshed in every 30sec.
Again the page has two different mode [Add/Edit] . The two links are used for running the page in different mode. You can see ASP.NET is keeping two versions of cache separately for Add mode and Edit mode.