|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
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.
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 thedirective's attribute. For more information, see .
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.
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.