Follow in Twitter & Facebook

Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools

Sunday, October 7, 2012

Partial Page(UserControl) Caching in Asp.Net

In this article we will discuss about caching in Asp.Net. You can also check my last article on Session state and Query String in Asp.Net.

Similar output caching,partial page caching enables you to cache only specific blocks of a webpage. For example, cache only the center of the page. Partial page caching is achieved with the caching of user can build your ASP.NET pages utilizing different user controls and then apply output caching  to the user controls you select.i.e it caches only the parts of the page that you want,leaving other parts of the page outside the reach of caching. This is a nice feature and if done correctly, it can lead pages that perform better.

UserControls are placed on multiple pages to maximize reuse.How ever when these usercontrols are cached with the @OutputCache directive's default attributes, they are cached on a pre-page basis. That means that even if a usercontrol outputs the identical HTML when placed on page.aspx as it does when placed on page2.aspx,its output is cached twice. By enabling the Shared = "true" attribute, the usercontrol's output can be shared among multiple pages and on sites that make heavy use of shared usercontrols.

<%@ OutputCache Duration="300" VaryByParam="*" Shared="true"%>

The resulting memory savings can be surprisingly large.As withall optimizations,test  both for correctness of output as well as memory usage.

protected void Page_Load()
if(PossiblyCachedUserControl != null)
//Place code manipulating PossiblyCachedUserControl here

0 on: "Partial Page(UserControl) Caching in Asp.Net"