Fragment Caching:
Fragment caching, which is new in ASP.NET, allows for the caching of portions of your output page.This is an excellent improvement in caching technique, and is best used when your application’s output page has content that changes constantly in addition to content that changes very little.While this method does not provide as much of a performance increase as output caching, it does increase performance for applications that would formerly have been unable to use any caching at all due to the strict requirements of output caching.
In some pages we have some dynamic content that needs to be updated regularly, as well as content that remains relatively static, For this we have a concept called Fragment caching.
This enables you to break your page into separate sections (fragments) that can be cached individually with their own caching options.

Using fragment caching is very similar to output caching. In fact, you call it in the same way as output caching by using the @OutputCache directive. Fragment caching is implemented by separating user controls out of your main page, and assigning caching parameters to each user control.This gives you a greater level of control over which portions of your page are cached.

For example take a user control and give @outputcache directive to that control.

     <%@ Control Language="VB" AutoEventWireup="false" CodeFile="fragmentCacheControl.ascx.vb" 
     Inherits="fragmentCacheControl" %>
    <%@ OutputCache Duration="60" VaryByParam="none"%>
'And add label control and in code-behind file lbl1.Text = "Time in UserControl: " & DateTime.Now Register this user control in web page like below.
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Fragementcaching.aspx.vb"
     Inherits="Fragementcaching" %>
    <%@ Register TagPrefix="fragement" TagName="control" Src="~/fragmentCacheControl.ascx" %>



    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <fragement:control ID="usercontrol1" runat="Server" /> 
        </div>
        </form>
    </body>
    </html>
 

And in code behind file write
Response.Write("Time in Main page: " & DateTime.Now)

If you execute this page two times are displaying. One from main page and another from user control. If you refresh the page, then you observed that main page time only changed but not user control time, because user control time is cached.


<< Previous 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 *