HttpCachePolicy.SetValidUntilExpires Method
.NET Framework 3.0
Specifies whether the ASP.NET cache should ignore HTTP Cache-Control headers sent by the client that invalidate the cache.
Namespace: System.Web
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
The SetValidUntilExpires method 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 cache invalidation headers to the Web server and evict the page from the cache. When the validUntilExpires parameter is true, ASP.NET ignores cache invalidation headers and the page remains in the cache until it expires.
The following code example demonstrates how to use the SetValidUntilExpires method to instruct that any cache invalidation headers sent by the client are ignored.
// 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.
get_Response().get_Cache().SetExpires(DateTime.get_Now().AddSeconds(60));
// Set the VaryByHeaders attribute with the value Accept-Language to true.
get_Response().get_Cache().get_VaryByHeaders().set_Item(
"Accept-Language" , true );
// ASP.NET ignores cache invalidation headers and the page remains in
// the cache until it expires.
get_Response().get_Cache().SetValidUntilExpires(true);
get_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.");
} //Page_Load
Community Additions
ADD
Show: