Share via


HttpCachePolicy.SetValidUntilExpires(Boolean) Método

Definición

Especifica si la caché de ASP.NET debe omitir los encabezados HTTP Cache-Control enviados por el cliente que invaliden la caché.

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

Parámetros

validUntilExpires
Boolean

true si la caché omite los encabezados de invalidación Cache-Control; en caso contrario, false.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el SetValidUntilExpires método para indicar que se omiten los encabezados de invalidación de caché enviados por el cliente.

<!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>

Comentarios

El SetValidUntilExpires método se establece en true automáticamente cuando se usa la directiva de página de alto nivel <%@ OutputCache … %> .

Este método se proporciona porque algunos exploradores, al actualizar una vista de página, envían encabezados de invalidación de caché HTTP al servidor web y expulsan la página de la memoria caché. Cuando el validUntilExpires parámetro es true, ASP.NET omite los encabezados de invalidación de caché y la página permanece en la memoria caché hasta que expire.

SetValidUntilExpiresse introduce en la versión 3.5 de .NET Framework. Para más información, vea Versiones y dependencias.

Se aplica a