Compartilhar via


HttpCachePolicy.SetValidUntilExpires(Boolean) Método

Definição

Especifica se o cache do ASP.NET deve ignorar cabeçalhos Cache-Control de HTTP enviados pelo cliente que invalida o cache.

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 se o cache ignora cabeçalhos de invalidação Cache-Control; caso contrário, false.

Exemplos

O exemplo de código a seguir demonstra como usar o SetValidUntilExpires método para instruir que todos os cabeçalhos de invalidação de cache enviados pelo cliente são ignorados.

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

Comentários

O SetValidUntilExpires método é definido automaticamente true quando a diretiva de página de alto nível <%@ OutputCache … %> é usada.

Esse método é fornecido porque alguns navegadores, ao atualizar um modo de exibição de página, enviam cabeçalhos de invalidação de cache HTTP para o servidor Web e removem a página do cache. Quando o validUntilExpires parâmetro é true, ASP.NET ignora cabeçalhos de invalidação de cache e a página permanece no cache até expirar.

SetValidUntilExpiresé introduzido no .NET Framework versão 3.5. Para saber mais, confira Versões e dependências.

Aplica-se a