【2】 페이지 출력 캐시
- , ASP.NET 。 , , 。 , , 。 , , 。 , , 。
-
- ASP.NET , aspx :
-
- <%@ OutputCache Duration="60" VaryByParam="none" %>
-
- Duration
-
- ( )。 。 , 。
-
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CacheWebApp._16_4_3.WebForm1" %>
-
- <%@ OutputCache Duration="60" VaryByParam="none" %>
-
- <html xmlns="http://www.w3.org/1999/xhtml" >
-
- <head runat="server">
-
- <title> </title>
-
- </head>
-
- <body>
-
- <form id="form1" runat="server">
-
- <div>
-
- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
-
- </div>
-
- </form>
-
- </body>
-
-
-
- </html>
-
- :
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- Label1.Text = DateTime.Now.ToString();
- }
- }
-
- <%@ OutputCache Duration="60" VaryByParam="none" %>, 。 , ,60 , 60 。
- VaryByParam
-
- POST GET / ( ) , 。 , none。 , (*)。
-
- : http://localhost:1165/16-4-3/WebForm1.aspx?p=1
- WebForm1.aspx :<%@ OutputCache Duration="60" VaryByParam="p" %>
-
- 60 , p , p 。
-
- WebForm1.aspx?p=1 , , p=2 。
-
- , :http://localhost:1165/16-4-3/WebForm1.aspx?p=1&n=1
-
- :<%@ OutputCache Duration="60" VaryByParam="p;n" %>
-
- ,@OutputCache 。@OutputCache :
-
- <%@ OutputCache Duration="#ofseconds"
-
- Location="Any | Client | Downstream | Server | None |
-
- ServerAndClient "
-
- Shared="True | False"
-
- VaryByControl="controlname"
-
- VaryByCustom="browser | customstring"
-
- VaryByHeader="headers"
-
- VaryByParam="parametername"
-
- CacheProfile="cache profile name | ''"
-
- NoStore="true | false"
-
- SqlDependency="database/table name pair | CommandNotification"
-
- %>
-
- CacheProfile
-
- Web.config 。 , ("")。
-
- :
-
- Web.config :
-
- <system.web>
-
- <caching>
-
- <outputCacheSettings>
-
- <outputCacheProfiles>
-
- <add name="CacheTest" duration="50" />
-
- </outputCacheProfiles>
-
- </outputCacheSettings>
-
- </caching>
-
- </system.web>
-
- :
-
- <%@ OutputCache CacheProfile="CacheTest" VaryByParam="none" %>
-
- :
-
- (.ascx ) @ OutputCache 。 , outputCacheSettings outputCacheProfiles 。 , 。
-
- , , , 。 , web.config , 。
-
- VaryByControl
-
- ( ID, )。
-
- ASP.NET @ OutputCache , VaryByParam 。
-
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="CacheWebApp._16_4_3.WebForm2" %>
-
- <%@ OutputCache Duration="60" VaryByParam="none" VaryByControl="DropDownList1" %>
-
- <html xmlns="http://www.w3.org/1999/xhtml" >
-
- <head runat="server">
-
- <title> </title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <%=DateTime.Now %>
- <br>
- <asp:DropDownList ID="DropDownList1" runat="server">
- <asp:ListItem>beijing</asp:ListItem>
- <asp:ListItem>shanghai</asp:ListItem>
- <asp:ListItem>guangzhou</asp:ListItem>
- </asp:DropDownList>
- <asp:Button ID="Button1" runat="server" Text=" " />
- </div>
- </form>
- </body>
-
- </html>
-
- 60 , GET POST ( VaryByParam , @ OutputControl )。 ID “DropDownList1” ( ), 。
-
- API
-
- Response Cache 。 System.Web.HttpCachePolicy。 HTTP ASP.NET 。 .NET Framework 1.x HttpCachePolicy ,.NET Framework 2.0 HttpCachePolicy 。 , ,SetOmitVarStar 。 HttpCachePolicy , 。
-
- SetExpires
-
- 。 DataTime , 。
-
- protected void Page_Load(object sender, EventArgs e)
- {
- // API
-
- // @OutputCache Duration
-
- Response.Cache.SetExpires(DateTime.Now.AddSeconds(10));
-
- Response.Cache.SetExpires(DateTime.Parse("6:00:00PM"));
-
- }
-
- , 60 , GET POST , “<%@ OutputCache Duration="60" VaryByParam="none" %>”。 6 。
-
- SetLastModified
-
- Last-Modified HTTP 。Last-Modified HTTP , 。 , 。 DataTime 。
-
- SetSlidingExpiration
-
- 。 。 true ,Cache-Control HTTP 。 IIS 。 False , , 。 HTTP 。 。
-
- SetOmitVaryStar
-
- ASP.NET 2.0 。 , vary:* 。 , HttpCachePolicy VaryByHeaders * , true; false。
-
- SetCacheability
-
- Cache-Control HTTP 。 。 , 。 HttpCacheability , NoCache、Private、Public、Server、ServerAndNoCache ServerAndPrivate( , MSDN)。 , HttpCacheability , , 。 , Private NoCache , 。 , 。
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
양식 제출 후 제출 버튼 비활성화텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.