ASP.Net/Response/Response Cache — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 18:30, 26 мая 2010

Cache control: Expires Absolute (VB.net)

   <source lang="csharp">

<%@ Page Language="vb" %> <html>

  <head>
     <title>Cacheing Output in ASP.NET</title>
     <script runat="server">
        Sub Page_Load()
           Response.CacheControl = "Public"
           Response.ExpiresAbsolute = DateTime.Now.AddSeconds(30)
           Message.Text = Now.ToString()
        End Sub
     </script>
  </head>

<body>

  <asp:label id="Message" runat="server"/>

</body> </html>

      </source>
   
  


Cache control: Expires (VB.net)

   <source lang="csharp">

<%@ Page Language="vb" %> <html>

  <head>
     <title>Cache control in ASP.NET</title>
     <script runat="server">
        Sub Page_Load()
           Response.CacheControl = "Public"
           Response.Expires = 2
           Message.Text = Now.ToString()
        End Sub
     </script>
  </head>

<body>

  <asp:label id="Message" runat="server"/>

</body> </html>

      </source>
   
  


Change Http Cache Policy (VB.net)

   <source lang="csharp">

<%@ Page Language="vb" %> <html>

  <head>
     <title>Cacheing Output in ASP.NET</title>
     <script runat="server">
        Sub Page_Load()
           Dim myCachePol As HttpCachePolicy
           myCachePol = Response.Cache
           myCachePol.SetExpires(DateTime.Now.AddSeconds(120))
           myCachePol.SetCacheability(HttpCacheability.Public)
           Message.Text = Now.ToString()
        End Sub
     </script>
  </head>

<body>

  <asp:label id="Message" runat="server"/>

</body> </html>

      </source>
   
  


Removing cache items (VB.net)

   <source lang="csharp">

<%@ Page Language="vb" %> <html>

  <head>
     <title>Removing cache items in ASP.NET</title>
     <script runat="server">
        Sub Page_Load()
           Cache("Key1") = "foo"
           Response.RemoveOutputCacheItem(Request.Path)
           If Not Cache("Key1") Is Nothing Then
              Message.Text = Cache("Key1")
           Else
              Message.Text = "Cache items for " & Request.Path & _
                 " removed."
           End If
        End Sub
     </script>
  </head>

<body>

  <asp:label id="Message" runat="server"/>

</body> </html>

      </source>