Sapna Malik
What is Fragment Caching in ASP.NET?
By Sapna Malik in ASP.NET on Sep 28 2009
  • kalit sikka
    Oct, 2009 26

    ASP.NET provides a mechanism for caching portions of pages, called page fragment caching. To cache a portion of a page, you must first encapsulate the portion of the page you want to cache into a user control. In the user control source file, add an OutputCache directive specifying the Duration and VaryByParam attributes. When that user control is loaded into a page at runtime, it is cached, and all subsequent pages that reference that same user control will retrieve it from the cache.

    <!— UserControl.ascx —>

    <%@ OutputCache Duration='60'
    VaryByParam='none' %>
    <%@ Control Language="'C#'" %>

    <script runat="server">
    protected void Page_Load(Object src, EventArgs e)
    {
    _date.Text = "User control generated at " +
    DateTime.Now.ToString();
    }
    </script>
    <asp:Label id='_date' runat="'server'" />

    Here I have user caching on user control, so when ever we used in a page , only partial page will be cached.

    http://kalitinterviewquestions.blogspot.com/

    • 0
  • Sapna Malik
    Sep, 2009 28

    Fragment Caching in asp.net

    • Fragment caching refers to the caching of individual user controls within a Web Form. 
    • Each user control can have independent cache durations and implementations of how the caching behavior is to be applied.
    • Fragment caching is useful when you need to cache only a subset of a page. 
    • Navigation bars, header, and footers are good candidates for fragment caching. 

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS