ASP.Net/Response/Response Cache

Материал из .Net Framework эксперт
Версия от 11:54, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Cache control: Expires Absolute (VB.net)

<%@ 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>



Cache control: Expires (VB.net)

<%@ 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>



Change Http Cache Policy (VB.net)

<%@ 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>



Removing cache items (VB.net)

<%@ 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>