Asp.Net Caching: Output Caching,Fragement Caching,Post Cache Substitution

Caching is a technique used in various aspects of computing to increase performance by decreasing access times for obtaining data. This is accomplished by retaining frequently accessed data within memory.



ASP.NET makes available three different types of caching, which, when used properly, can greatly increase the overall performance of your application.
These types are as follows:

_ Output Caching
_ Fragment Caching
_ Post Cache Substitution
_ Data Caching

Output Caching:
Output caching basically caches the entire content of an output Web page.This can be very useful when the content of your pages changes very little.
Output caching provides the capability to cache response content generated from dynamic pages for the purpose of increasing application performance. This form of caching should be applied when the content of your page is somewhat static.
Various options can be set for output caching including the duration. In order for a page to be cached using output caching, it must have a valid expiration or validation policy.These options can be set either through the Using the @ OutputCache Directive

When the @ OutputCache directive is used at the top of the page,ASP.NET basically uses the Page.InitOutputCache method to translate the directive parameters into HttpCachePolicy class methods. To set the expiration of a page you intend to cache, you can use the following code at the top of the page:

<% @ OutputCache Duration="60" VaryByParam="None" %>

This sets the cache duration for this page to 60 seconds.
The VaryByParam attribute is one of three attributes used to control caching of multiple pages by the @ OutputCache directive.These attributes are as follows:

_ VaryByParam
_ VaryByHeader
_ VaryByCustom

When ASP.NET generates the content of your page, the output can vary based on values that have been passed to the page. By using the VaryByParam attribute, you can control the caching of these pages based on a GET query string or POST parameters. By specifying the GET query string parameters or POST parameters using this attribute, each request received for that parameter using a different value will be cached.
For example, if you specified the “id” GET query string parameter, each request received with a different name value will be cached separately.The syntax for setting a 60-second cache with the “id” parameter is as follows:

<% @ OutputCache Duration="60" VaryByParam="id" %>

Next >>

Recent Articles

CLR integartion in SQL Server
Create, Read and Write Files in .Net
Message Queue in .Net
Deploy Asp.Net Web Site
Queues in Vb.Net
If you have any queries or doubts post at Forum
Share on Facebook
Responses(post your response or comments below)
Name *

Email * (won't be published)

Response *