Fragment Caching - Caching parts of a Page

Caching is one of the recommended techniques to improve the performance of web applications by avoiding repeated requests to the server.

It serves the purpose for faster response as well as reducing the load to the Server.

Output caching can be enabled easily by just including the following code in the Top of the aspx page

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

This would result in the whole page being cached.

However, there will be situations where we would like to cache only sections of page rather than the whole page. There may be sections of the page where the information gets updated every second or so and these sections should not cached.

This can be implemented in ASP.NET using Fragment Caching. Fragment Caching is the technique by which we can cache a sections of the page instead of caching the whole page.

This is accomplished by dividing the pages into usercontrols and caching the individual usercontrols.

Say we have a page which has 5 sections. We can split the static sections into usercontrols and cache them such that only that portion of the page is cached..

The syntax for fragment caching is similar to output caching

<%@ OutputCache Duration="1200" VaryByControl="None" %>

We can therefore cache only portions of the page and avoid the whole page being cached.

Note the VaryByControl attribute. It is unique to user controls caching and we can specify the ID of a webcontrol (ex. DropDownList) to invalidate the cache if the control's selection / property is changed.

Caching has been improved a lot with the .NET 2.0 version which is scheduled to be released sometime during early 2005.

posted @ Monday, April 25, 2005 7:53 AM

Print

Comments on this entry:

# re: Fragment Caching - Caching parts of a Page

Left by sparsha at 8/23/2005 2:55 PM
Gravatar
thanks that helped a lot

# re: Fragment Caching - Caching parts of a Page

Left by Sam at 12/27/2007 9:24 PM
Gravatar
Gr8 info...

# re: Fragment Caching - Caching parts of a Page

Left by rashmi at 9/24/2008 6:33 PM
Gravatar
when i cashe user user control. click even on user control will not work, for example menu conterol for master page. if create user control for menu and cashe that usercontrol. click event will not work till it expires duration

# re: Fragment Caching - Caching parts of a Page

Left by aji at 8/3/2009 4:48 PM
Gravatar
sdsa ds

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345