Поделиться через


Caching ASP.NET Pages

ASP.NET allows you to cache some or all of the response generated by an ASP.NET page, referred to in ASP.NET as output caching. You can cache the page at the browser making the request, at the Web server responding to the request, and at any other cache-capable devices, such as proxy servers, that are in the request or response stream. Caching provides a powerful way for you to increase the performance of your Web applications. Caching allows subsequent requests for a page to be satisfied from the cache so the code that initially creates the page does not have to be run again. Caching your site's most frequently accessed pages can substantially increase your Web server's throughput, commonly measured in requests per second.

You can specify cache settings declaratively in a page or configuration file, or programmatically using a cache API. For more information, see Setting the Cacheability of a Page.

You can cache pages based on the values of query string parameters or form variables (control values). Caching based on these types of values must be explicitly enabled by using the @ OutputCache directive's VaryByParam attribute. For more information, see Caching Multiple Versions of a Page.

When a cached page is requested by a user, ASP.NET determines whether the cached output is still valid based on the cache policy you have defined for the page. If the output is valid, the cached output is sent to the client and the page is not re-processed. ASP.NET allows you to run code during this validation check so that you can write custom logic to check whether the page is valid. For more information see How to: Check the Validity of a Cached Page.

Sometimes it is impractical to cache an entire page because portions of the page might need to change on each request. In those cases, you can cache a portion of a page. ASP.NET provides functionality to cache only portions of an ASP.NET page. For more information see Caching Portions of an ASP.NET Page.

See Also

Tasks

How to: Set the Cacheability of an ASP.NET Page Declaratively

How to: Set a Page's Cacheability Programmatically

How to: Set Expiration Values for ASP.NET Page Caching

How to: Check the Validity of a Cached Page

How to: Cache Page Output with File Dependencies

How to: Cache Page Output with Cache Key Dependencies

Concepts

ASP.NET Caching Overview

Setting the Cacheability of a Page

Caching Multiple Versions of a Page