
HttpCachePolicy | 489
System.Web
Namespace
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Hierarchy
System.Object ➝ System.ValueType ➝ System.Enum(System.IComparable, System.IFor-
mattable, System.IConvertible)
➝ HttpCacheability
Passed To
HttpCachePolicy.SetCacheability( )
HttpCachePolicy
System.Web (system.web.dll)
sealed class
This class allows you to configure “page” or output caching for an ASP.NET applica-
tion, which stores a fully rendered page for automatic reuse. A cached page will be
used for GET requests until it expires, as long as the URL request does not have
different query string arguments. A cached page will not be used for POST requests, so
postbacks (such as when a user clicks on button) will bypass the cached page. (This
behavior is slightly and mysteriously different than just using the <OutputCache> page
directive, which always reuses the cached page for any type of request when the VaryBy-
Param attribute is set to None.) To specifically modify this behavior, you can use the
VaryByParams property and the HttpCacheVaryByParams class.
To enable caching for a page, use the SetCacheability( ) method to set the page’s visibility
to Public so it can be stored in the shared cache. Then use the SetExpires( ) method to
determine the lifetime of the page in the cache. For example, Response.Cache.SetEx-
pires(DateTime.Now.AddSeconds(60)); ...