An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

Fragment Caching - Caching parts of a Page

Monday, April 25, 2005 7:53 AM
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.

Feedback

# re: Fragment Caching - Caching parts of a Page

thanks that helped a lot 8/23/2005 2:55 PM | sparsha

# re: Fragment Caching - Caching parts of a Page

aadsdasdasdasd 3/7/2006 8:49 AM | aaa

# re: Fragment Caching - Caching parts of a Page

gdfgdfg 8/24/2006 1:02 PM | tg

# re: Fragment Caching - Caching parts of a Page

Gr8 info... 12/27/2007 9:24 PM | Sam

Post a comment





 

Please add 2 and 5 and type the answer here: