Declaratively controls the output caching policies of an ASP.NET page or a user control contained in a page. For more information about the output cache, see ASP.NET Caching.
<%@ OutputCache Duration="#ofseconds" Location="Any | Client | Downstream | Server | None | ServerAndClient " Shared="True | False" VaryByControl="controlname" VaryByCustom="browser | customstring" VaryByHeader="headers" VaryByParam="parametername" VaryByContentEncoding="encodings" CacheProfile="cache profile name | ''" NoStore="true | false" SqlDependency="database/table name pair | CommandNotification" ProviderName="Provider Name" %>
If a Web Forms page requires authorization to be viewed by a user, the output cache sets the Cache-Control HTTP header to private. For more information on all these subjects, see Caching ASP.NET Pages.
If you set the Shared attribute to true, cached user control output can be accessed by multiple Web Forms pages. If you do not set it to true, the default behavior is to cache one version of user control output for each page that contains that user control. You can potentially save a significant amount of memory by enabling the Shared attribute. For more information, see Caching Portions of an ASP.NET Page.
The following code example demonstrates how you can set the duration for which a page or user control is output cached.
<%@ OutputCache Duration="100" VaryByParam="none" %>
The next code example demonstrates how you can instruct the output cache to cache a page or user control by its location and count form parameters from a form's POST method or from a query string. Each HTTP request that arrives with a different location or count parameter (or both) is cached for ten seconds. Any subsequent requests with the same parameter values are satisfied from the cache until the entry expires.
<%@ OutputCache Duration="10" VaryByParam="location;count" %>