Hi
The
partial page caching approach works very well for scenarios where most of the
page content is dynamic and/or it is easy to encapsulate cached content into
isolated user controls. The concept does not work well for the reverse
scenario, when most of page content should be cached and only a very small
portion is dynamically built. For example, consider a page displaying static
data but only the username displayed is dynamic. In this case it might not be
possible to cache the entire page because of the username, which is dynamic.
Post-Cache
Substitution is the answer for the above situation. This control is available
in asp.net 2.0. This feature is aimed at optimizing the cached pages. Earlier
we would use User Control to cache regions in the page. But with Post Cache
substitution we can cache a full page and allow a small part of the page to be
updated dynamically. For this we have to identify the regions that should be
exempted from caching.
We
can place a substitution control (server side control) where dynamic content is
required. We have to set the MethodName property to the callback method on the
page. This method has to be a static method on the controls container.
The
code for working with substitution control is
<%@ OutputCache Duration="60" VaryByParam="none" %>
<script language="C#" runat="server">
public static String GetTheCurrentTime (HttpContext context) {
return System.dateTime.Now.ToString();
}
</script>
Some static Cached content
<form runat="server">
<h2>The current Time is <asp:Substitution MethodName="GetTheCurrentTime" />!</h2>
</form>
Here
I am returning the current time but with the HttpContext parameter to the
callback we can also retrieve the parameters like query string, Session
variable, authentication detail etc.
Hope
this helps
Thanks
Vikram