JavaScript Editor jscript editor     Web designer 



Main Page

The cacheability of a page or user control refers to whether a page can be cached on a device during the page's response life cycle. Devices that can cache a page include the browser making the request, the Web server responding to the request, and any other cache-capable devices, such as proxy servers, that are in the request or response stream.

When a Web server sends a response to the requesting browser, the server includes in the response a Cache-Control field in the HTTP header that defines the devices on which the page can be cached. Depending on the needs of your application, you can define which devices should or should not cache individual ASP.NET pages. For example, you might want the cacheability settings for a user logon page to be different from those for a page that displays a selection of products from a catalog. In the case of the logon page, for security reasons you might want to cache the page only on the server, while the catalog page can be cached on any device.

For ASP.NET pages, you can set cacheability by using values in the HttpCacheability enumeration. The enumeration has the following values. The first three map directly to Cache-Control HTTP header settings, and the last three are special values.

You can set a page's cacheability declaratively by including a Location attribute in the @ OutputCache directive and specifying one of the OutputCacheLocation enumeration values. You can also set a page's cacheability programmatically using the SetCacheability method to specify an HttpCacheability value for the page. The method is accessible through the Cache property of the Response class.

NoteNote

If you use the @В OutputCache directive to set your page's cacheability, you must declare the Duration attribute and either the VaryByControl attribute or the VaryByParam attribute along with the Location attribute. The Duration attribute must be set to a value larger than zero. You can set the VaryByParam attribute to "None" if you do not want to use the functionality of the VaryByParam or VaryByControl parameters. For more information, see How to: Set Expiration Values for ASP.NET Page Caching and Caching Multiple Versions of a Page.

As an alternative to setting a page's cacheability using the @В OutputCache directive, you can create a cache profile in your application's Web.config file and then reference the profile in your page. For more information, see Cache Configuration in ASP.NET.

See Also



JavaScript Editor jscript editor     Web designer 
R7