Fragment caching is much like output caching except that it refers to caching portions of web pages and only at the server. In ASP.NET this is done by encapsulating portions of pages in user controls and then specifying caching rules. There can be any number of user controls on a web page, and each user control maintains its own caching. Fragment caching uses the same attributes of the OutputCache page directive and the HttpCachePolicy class, with the exception of using the VaryByControl parameter to create variations of the page.
In the following example we will duplicate the previous Output Caching example, except we will use a user control instead of a web form.
STEP BY STEP
1. Add a new user control to your Visual Studio C# application.
2. Follow steps 2 through 5 in the previous How to Use Output Caching example, except use a user control instead of a web form.
3. Replace the Page directive OutputCache at the top of the user control’s HTML as follows.
From: <%@ OutputCache duration="3600" VaryByParam="ddlCountry"%>
To: <%@ OutputCache duration="3600" VaryByControl="ddlCountry"%>
Note: if not using the VaryByControl parameter then the VaryByParam attribute will be used: <%@ OutputCache duration="3600" VaryByParam="none"%>
4. Place the user control on a web form.
5. Visit the web page from several different computers and you will see the same data and report time for each country.