Cache (partial) pages based on custom strings

Source: Internet
Author: User

For example, a website has a header. the ascx user control. Each page calls this control as the "page header". You can directly cache this user control to submit the performance. However, the current header. to display the login name of the login user, the ascx user control cannot directly use the following cache method:

<%
@ Outputcache duration
=
"
86400
"
Varybyparam
=
"
None
"
 
%>

In this case, you can use the "cache pages based on custom strings" method as follows:

<% @ Outputcache duration = " 86400 " Varybyparam = " None " Varybycustom = " Headerpagekey "   %>

Then override the getvarybycustomstring method in the global class.

Public   Override   String Getvarybycustomstring (httpcontext context, String Custom)
{
If (Custom = " Headerpagekey " )
{
// Cache header. ascx Control
If (Context. Request. isauthenticated)
{
Return Context. User. Identity. Name;
}
Else
{
Return   " Noauthenticated_user " ;
}
}
Return   Base . Getvarybycustomstring (context, custom );
}

If the user does not log on, a version is cached. if the user has logged on, another version is cached Based on the login name. Haha, a version is cached for each user. In this way, it should be said that it is not a good solution.

The above cache technology can refer to the http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/cpguide/html/cpconcachingversionsofpagebasedonparameters. asp

In addition, this cache method is also used in mspetshop3.0. Different versions are cached based on request. querystring and whether to log on to the cache. However, this cache does not seem to be enabled by default.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.