This documentation is archived and is not being maintained.

HttpCachePolicy.SetValidUntilExpires Method

Specifies whether the ASP.NET cache should ignore HTTP Cache-Control headers sent by the client that invalidate the cache.

[Visual Basic]
Public Sub SetValidUntilExpires( _
   ByVal validUntilExpires As Boolean _
)
[C#]
public void SetValidUntilExpires(
 bool validUntilExpires
);
[C++]
public: void SetValidUntilExpires(
 bool validUntilExpires
);
[JScript]
public function SetValidUntilExpires(
   validUntilExpires : Boolean
);

Parameters

validUntilExpires
true if the cache ignores Cache-Control invalidation headers; otherwise, false.

Remarks

SetValidUntilExpires is set to true automatically when the high-level <%@ OutputCache %> page directive is used.

This method is provided because some browsers, when refreshing a page view, send HTTP cach invalidation headers to the Web server and evict the page from the cache. When SetValidUntilExpires is set to true, ASP.NET ignores cache invalidation headers and the page remains in the cache until it expires.

Example

[Visual Basic] 
' 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

[C#] 
// 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.");
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpCachePolicy Class | HttpCachePolicy Members | System.Web Namespace

Show: