【2】 페이지 출력 캐시


  
  
  
  
  1. , ASP.NET 。 , , 。 , , 。 , , 。 , , 。  
  2.  
  3. ASP.NET , aspx :  
  4.  
  5. <%@ OutputCache Duration="60" VaryByParam="none" %>  
  6.  
  7. Duration    
  8.  
  9. ( )。 。 , 。  
  10.  
  11. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CacheWebApp._16_4_3.WebForm1" %>  
  12.  
  13. <%@ OutputCache Duration="60" VaryByParam="none" %>  
  14.  
  15. <html xmlns="http://www.w3.org/1999/xhtml" >  
  16.  
  17. <head runat="server">  
  18.  
  19.     <title> </title>  
  20.  
  21. </head>  
  22.  
  23. <body>  
  24.  
  25.     <form id="form1" runat="server">  
  26.  
  27.     <div>  
  28.  
  29.         <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>  
  30.  
  31.     </div>  
  32.  
  33.     </form>  
  34.  
  35. </body>  
  36.  
  37.    
  38.  
  39. </html>  
  40.  
  41. :  
  42.        protected void Page_Load(object sender, EventArgs e)  
  43.         {  
  44.             if (!IsPostBack)  
  45.             {  
  46.                Label1.Text = DateTime.Now.ToString();  
  47.             }  
  48.         }  
  49.  
  50.      <%@ OutputCache Duration="60" VaryByParam="none" %>, 。 , ,60 , 60 。  
  51. VaryByParam  
  52.  
  53.  POST   GET  / ( ) , 。 ,  none。 ,  (*)。  
  54.  
  55. : http://localhost:1165/16-4-3/WebForm1.aspx?p=1  
  56. WebForm1.aspx :<%@ OutputCache Duration="60" VaryByParam="p" %>  
  57.  
  58. 60 , p , p 。  
  59.  
  60. WebForm1.aspx?p=1 , , p=2 。  
  61.  
  62. , :http://localhost:1165/16-4-3/WebForm1.aspx?p=1&n=1  
  63.  
  64. :<%@ OutputCache Duration="60" VaryByParam="p;n" %>   
  65.  
  66. ,@OutputCache  。@OutputCache :  
  67.  
  68. <%@ OutputCache Duration="#ofseconds" 
  69.  
  70.    Location="Any | Client | Downstream | Server | None |  
  71.  
  72.      ServerAndClient "  
  73.  
  74.    Shared="True | False" 
  75.  
  76.    VaryByControl="controlname" 
  77.  
  78.    VaryByCustom="browser | customstring" 
  79.  
  80.    VaryByHeader="headers" 
  81.  
  82.    VaryByParam="parametername" 
  83.  
  84.    CacheProfile="cache profile name | ''" 
  85.  
  86.    NoStore="true | false" 
  87.  
  88.    SqlDependency="database/table name pair | CommandNotification" 
  89.  
  90. %>  
  91.  
  92. CacheProfile  
  93.  
  94. Web.config 。 ,  ("")。  
  95.  
  96. :  
  97.  
  98. Web.config :  
  99.  
  100. <system.web>  
  101.  
  102.     <caching>  
  103.  
  104.         <outputCacheSettings>  
  105.  
  106.             <outputCacheProfiles>  
  107.  
  108.                 <add name="CacheTest" duration="50" />  
  109.  
  110.             </outputCacheProfiles>  
  111.  
  112.         </outputCacheSettings>  
  113.  
  114. </caching>  
  115.  
  116. </system.web>  
  117.  
  118. :  
  119.  
  120. <%@ OutputCache CacheProfile="CacheTest"  VaryByParam="none" %>  
  121.  
  122. :  
  123.  
  124. (.ascx  )  @ OutputCache  。 ,  outputCacheSettings   outputCacheProfiles  。 , 。  
  125.  
  126. , , , 。 , web.config , 。  
  127.  
  128. VaryByControl  
  129.  
  130. ( ID, )。  
  131.  
  132.  ASP.NET   @ OutputCache  ,  VaryByParam  。  
  133.  
  134. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="CacheWebApp._16_4_3.WebForm2" %>  
  135.  
  136. <%@ OutputCache Duration="60" VaryByParam="none" VaryByControl="DropDownList1" %>  
  137.  
  138. <html xmlns="http://www.w3.org/1999/xhtml" >  
  139.  
  140. <head runat="server">  
  141.  
  142.     <title> </title>  
  143. </head>  
  144. <body>  
  145.     <form id="form1" runat="server">  
  146.     <div>  
  147.          <%=DateTime.Now %>         
  148.         <br>  
  149.     <asp:DropDownList ID="DropDownList1" runat="server">  
  150.         <asp:ListItem>beijing</asp:ListItem>  
  151.         <asp:ListItem>shanghai</asp:ListItem>  
  152.         <asp:ListItem>guangzhou</asp:ListItem>  
  153.         </asp:DropDownList>  
  154.         <asp:Button ID="Button1" runat="server" Text=" " />  
  155.     </div>  
  156.     </form>  
  157. </body>  
  158.  
  159. </html>  
  160.  
  161. 60 , GET POST ( VaryByParam , @ OutputControl )。 ID “DropDownList1” ( ), 。  
  162.  
  163. API  
  164.  
  165. Response Cache 。 System.Web.HttpCachePolicy。 HTTP ASP.NET 。 .NET Framework 1.x HttpCachePolicy ,.NET Framework 2.0 HttpCachePolicy 。 , ,SetOmitVarStar 。 HttpCachePolicy , 。  
  166.  
  167. SetExpires  
  168.  
  169. 。 DataTime , 。  
  170.  
  171.         protected void Page_Load(object sender, EventArgs e)  
  172.         {  
  173.             //  API  
  174.  
  175.             // @OutputCache Duration  
  176.  
  177.             Response.Cache.SetExpires(DateTime.Now.AddSeconds(10));  
  178.  
  179.             Response.Cache.SetExpires(DateTime.Parse("6:00:00PM"));  
  180.  
  181.         }  
  182.  
  183. , 60 , GET POST , “<%@ OutputCache Duration="60" VaryByParam="none" %>”。 6 。  
  184.  
  185. SetLastModified  
  186.  
  187. Last-Modified HTTP 。Last-Modified HTTP , 。 , 。 DataTime 。  
  188.  
  189. SetSlidingExpiration  
  190.  
  191. 。 。 true ,Cache-Control HTTP 。 IIS 。 False , , 。 HTTP 。 。  
  192.  
  193. SetOmitVaryStar  
  194.  
  195. ASP.NET 2.0 。 , vary:* 。 , HttpCachePolicy VaryByHeaders * , truefalse。  
  196.  
  197. SetCacheability  
  198.  
  199.      Cache-Control HTTP 。 。 , 。 HttpCacheability , NoCache、Private、Public、Server、ServerAndNoCache ServerAndPrivate( , MSDN)。 , HttpCacheability , , 。 , Private NoCache , 。 , 。 

좋은 웹페이지 즐겨찾기