Petshop output cache settings
Petshop Of Web In the upper part of the page Controlheader It is related to the user's login status, so it is set Varybycustom The cached version that identifies different login statuses of users. While Category Because pages may be accessed in large quantities and the data volume is large, it is necessary to cache them. However, due to the randomness of the data, different versions exist, for example, different types Category And even different data pages are displayed on different pages. Varybycustom Attribute to cache pages of different versions.
Let's look at the specific implementation. Code :
Varybycustom You can customize any text required by the output cache. Besides Outputcache In addition to declaring this attribute in the Command, we haveProgramOf Global. asax In the Code declaration block of the file, rewrite Getvarybycustomstring To specify the output cache behavior for the custom string.
For example:
<% @ Outputcache varybyparam = "NONE" varybycustom = "categorypagekey" location = "server" Duration = "43200" %>
Here Varybycustom Defined Categorypagekey In Global. asax Which must be defined Categorypagekey This character creates the output cache behavior, see the following code.
Public Override StringGetvarybycustomstring (httpcontext context, string Arg ){
StringCachekey = "";
Switch(ARG ){
Case"Categorypagekey ":
If(Request. isauthenticated =True){
Cachekey = "qqq" + context. Request. querystring ["category_id"] + context. Request. querystring ["requestedpage"];
}
Else{
Cachekey = "AAA" + context. Request. querystring ["category_id"] + context. Request. querystring ["requestedpage"];
}
Break;
Case"Searchpagekey ":
If(Request. isauthenticated =True){
Cachekey = "qqq" + context. Request. querystring ["search_text"] + context. Request. querystring ["requestedpage"];
}
Else{
Cachekey = "AAA" + context. Request. querystring ["search_text"] + context. Request. querystring ["requestedpage"];
}
Break;
Case"Productpagekey ":
If(Request. isauthenticated =True){
Cachekey = "qqq" + context. Request. querystring ["name"] + context. Request. querystring ["product_id"] + context. Request. querystring ["requestedpage"];
}
Else{
Cachekey = "AAA" + context. Request. querystring ["name"] + context. Request. querystring ["product_id"] + context. Request. querystring ["requestedpage"];
}
Break;
Case"Productdetailspagekey ":
If(Request. isauthenticated =True){
Cachekey = "qqq" + context. Request. querystring ["item_id"] + context. Request. querystring ["requestedpage"];
}
Else{
Cachekey = "AAA" + context. Request. querystring ["item_id"] + context. Request. querystring ["requestedpage"];
}
Break;
Case"Userid ":
If(Request. isauthenticated =True){
Cachekey = "userid_in ";
}
Else{
Cachekey = "userid_out ";
}
Break;
}
ReturnCachekey;
}
From aboveCategorypagekeyWhen the request page containsWhen you request a data page displayed on a certain page of category_id, the call is cached (the page is cached naturally ).