HttpCachePolicy.SetValidUntilExpires(Boolean) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
キャッシュを無効にするクライアントから送信された HTTP Cache-Control ヘッダーを、ASP.NET キャッシュで無視するかどうかを指定します。
public:
void SetValidUntilExpires(bool validUntilExpires);
public void SetValidUntilExpires(bool validUntilExpires);
member this.SetValidUntilExpires : bool -> unit
Public Sub SetValidUntilExpires (validUntilExpires As Boolean)
パラメーター
- validUntilExpires
- Boolean
true キャッシュが無効ヘッダー Cache-Control 無視する場合は a0/>。それ以外の場合は false。
例
次のコード例では、 SetValidUntilExpires メソッドを使用して、クライアントから送信されたキャッシュ無効化ヘッダーが無視されるように指示する方法を示します。
<!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>
注釈
SetValidUntilExpires メソッドは、高レベルの<%@ OutputCache … %> ページ ディレクティブが使用されるときに自動的にtrueに設定されます。
このメソッドは、一部のブラウザーでページ ビューを更新するときに、HTTP キャッシュ無効化ヘッダーを Web サーバーに送信し、ページをキャッシュから削除するためです。
validUntilExpires パラメーターが true の場合、ASP.NET はキャッシュ無効化ヘッダーを無視し、ページは有効期限が切れるまでキャッシュに残ります。
SetValidUntilExpires は、.NET Framework バージョン 3.5 で導入されています。 詳細については、「 バージョンと依存関係」を参照してください。