Actually there are four types of Caching :
- Page Output Caching
- Partial Caching
- DataSource Caching
- Data Caching
Page Output Caching :
Enable you to cache the entire rendered contents of the whole page in memory (Every thing in ViewSource ) so when the user request the same page next time ,the page is retrieved from the caching memory.
Note :
Fiddler tool enable you to view the row request and response HTTP trafic for testing mode.
How to do:
- There is no guarantee that a page will be cached for the amount of time that you specify. When server memory resources become low, items are automatically evicted from the cache
- the page by default cached in multiple locations :Browser , Proxy server and Web server
- Duration attribute measures by Seconds
- You can cache the page based on the parameter (Query Strigng param or Form param) so in above example not required parameter so the value is "none"
../PageCachingByParam.aspx?id=12 and
./PageCachingByParam.aspx?id=15]
and separate page content is generated for each of them, the directive should be:
Note:
- To specify multiple parameters, use semicolon to separate the parameter names. If we specify the VaryByParam attribute as *, the cached content is varied for all parameters passed through the querystring.
Note:
- Each time your select from the dropdownlist with diff value ,the entire page will cached.
Note
A better way to create different cached versions of a page that depend on the type of browser being used to request the page is to use the VaryByCustom attribute. This attribute accepts the special value browser (IE 5.0 is diff than IE 6.0 or IE 6.0 is diff than Firefox ...)
By using VaryByCustom ,you can specify a custom method that determines when diff cache version of a page is generated. Let us see the example :
- In Global.asax , write this code :
{
if (String.Compare(custom, "css") == 0)
{
return Request.Browser.SupportsCss.ToString();
}
return base.GetVaryByCustomString(context, custom);
}
2.create a page as :
You can use the Location attribute of the directive to specify where a page is cached. This attribute accepts the following values:
Any The page is cached on the browser, proxy servers, and web server (the default value).
Client The page is cached only on the browser.
Downstream The page is cached on the browser and any proxy servers, but not the web server.
None The page is not cached.
Server The page is cached on the web server, but not the browser or any proxy servers.
ServerAndClient The page is cached on the browser and web server, but not on any proxy servers.
There are situations in which you might need to modify this default behavior. For example, if you are caching private information, then you don't want to cache the information on the web server or any proxy servers.
Ex :
Creating a Page Output Cache File Dependency:That means when a file is modified the cache page removed from the memory and reloaded again. Let us see this example :
this page displays the contents of an XML file in a GridView
You can remove a page from the cache programmatically by using the Response.RemoveOutputCacheItem() method
Let us assume that we have two pages , the first is List.aspx (to List all products) and the second is AddNew.aspx(to add new product) when adding new product we want to remove the List page from the cache : and Add Event()
HttpResponse.RemoveOutputCacheItem(Page.ResolveUrl("~/MovieList.aspx"));
Response.Redirect("~/MovieList.aspx");
Manipulating the Page Output Cache Programmatically:
Creating Page Output Cache Profiles:
then to apply to a particular page :
Finally, Page Output Cache is fine when the page content is the same for all request.
Ref :
- Code Project WebSite
- Unleashed ASP.NET 2.0 book
- AppDev Video
1 comment:
You write very well.
Post a Comment