Sdílet prostřednictvím


HttpCachePolicy.SetValidUntilExpires(Boolean) Metoda

Definice

Určuje, jestli má mezipaměť ASP.NET ignorovat hlavičky HTTP Cache-Control odeslané klientem, který mezipaměť zneplatňuje.

public:
 void SetValidUntilExpires(bool validUntilExpires);
public void SetValidUntilExpires (bool validUntilExpires);
member this.SetValidUntilExpires : bool -> unit
Public Sub SetValidUntilExpires (validUntilExpires As Boolean)

Parametry

validUntilExpires
Boolean

truepokud mezipaměť ignoruje Cache-Control hlavičky neplatných dat; jinak . false

Příklady

Následující příklad kódu ukazuje, jak pomocí SetValidUntilExpires metody instruovat, že všechny hlavičky zneplatnění mezipaměti odeslané klientem jsou ignorovány.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
<script language="C#" runat="server">

// The following example demonstrates the SetValidUntilExpires method of the
// HttpCachePolicy class. The SetValidUntilExpires method is set to true so 
// that the ASP.NET cache ignores the HTTP Cache-Control headers and the page 
// remains in the cache until it expires.

void Page_Load(object Sender, EventArgs e)
{
   // Set the expiration time for the page.
   Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
   // Set the VaryByHeaders attribute with the value Accept-Language to true.
   Response.Cache.VaryByHeaders["Accept-Language"] = true;
   // ASP.NET ignores cache invalidation headers and the page remains in 
   // the cache until it expires.
   Response.Cache.SetValidUntilExpires(true);
   Response.Write("The SetValidUntilExpires method is set to true and ASP.NET cache should " + 
      "ignore the Cache-Control headers sent by the client that invalidate the cache.");
}

</script>
</head>
<body></body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
<script language="VB" runat="server">

' The following example demonstrates the SetValidUntilExpires method of the
' HttpCachePolicy class. The SetValidUntilExpires method is set to true so that
' the ASP.NET cache ignores the HTTP Cache-Control headers and the page remains 
' in the cache until it expires.

Sub Page_Load(Sender As Object, e As EventArgs)
   ' Set the expiration time for the page.
   Response.Cache.SetExpires(DateTime.Now.AddSeconds(60))
   ' Set the VaryByHeaders attribute with the value Accept-Language to true.
   Response.Cache.VaryByHeaders("Accept-Language") = True
   ' ASP.NET ignores cache invalidation headers and the page remains in
   ' the cache until it expires.
   Response.Cache.SetValidUntilExpires(True)
   Response.Write("The SetValidUntilExpires method is set to true and the ASP.NET cache will " _
      & " ignore the Cache-Control headers sent by the client that invalidate the cache.")
End Sub 'Page_Load

</script>
</head>
<body></body>
</html>

Poznámky

Metoda SetValidUntilExpires je nastavena automaticky true při použití direktivy stránek vysoké úrovně <%@ OutputCache … %> .

Tato metoda se poskytuje, protože některé prohlížeče při aktualizaci zobrazení stránky odesílají hlavičky zneplatnění mezipaměti HTTP webovému serveru a vyřadí stránku z mezipaměti. validUntilExpires Pokud je trueparametr , ASP.NET ignoruje záhlaví zneplatnění mezipaměti a stránka zůstane v mezipaměti, dokud nevyprší platnost.

SetValidUntilExpiresje zaveden v .NET Framework verze 3.5. Další informace najdete v tématu Verze a závislosti.

Platí pro