Cache | page | string
For example, the site has a Header.ascx user control, each page calls this control as "page Head", can directly cache this user control can submit performance, however, Now this Header.ascx user control will display the login name of the login user, so you cannot use the following caching method directly:
<% @ OutputCache Duration = "86400" VaryByParam = "None"%>
This is the time to use the "cache page according to custom string" method, as follows:
<%@ OutputCache duration= "86400" varybyparam= "None" varybycustom= "Headerpagekey"%>
Then rewrite the method in the global class GetVaryByCustomString
public override string GetVaryByCustomString (HttpContext context, String custom)
{
if (custom== "Headerpagekey")
{
// Caching Header.ascx Controls
if (context. request.isauthenticated)
{
return context. User.Identity.Name;
}
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; Else
{
return "Noauthenticated_user";
}
}
return base. GetVaryByCustomString (context, custom);
}
If the user does not log in, then cache a version, if the login, then the different cache according to the name of the other version, Haha, for each user has cached a version, this should be said is not a good solution.
The above caching technology can refer to http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpguide/html/ Cpconcachingversionsofpagebasedonparameters.asp
In addition, this caching method is used in MSPetShop3.0, which caches different versions depending on the request.querystring and whether it is logged on, but the cache does not seem to be turned on by default.