Use the @OutputCache page directive to cache a Web form in the server’s memory. The @OutputCache directive’s Duration attribute controls how long the page is cached.
<%@ OutputCache Duration="60" VaryByParam="None" %>
The first time any user requests this Web form, the server loads the response in memory and retains that response for 60 seconds. Any subsequent requests during that time receive the cached response.
You can also cache multiple responses from a single Web form using the VaryByHeaders or VaryByCustom attribute. For example, the following OutputCache directive caches different responses based on the requested language:
<%@ OutputCache Duration="120" VaryByParam="None" VaryByHeader="Accept-Language" %>
<%@ OutputCache Duration="5" VaryByParam="None" Location="Any" %>
Table 12-2. OutputCache Location
Any
HttpCacheability.Server
Any available location: client, proxy server, or host server.
Client
HttpCacheability.Private
Client on which the request originated.
Downstream
HttpCacheability.Public
Client or proxy server.
None
HttpCacheability.NoCache
No location. This setting disables caching.
Server
HttpCacheability.ServerAndNoCache
Host server on which request is processed.
ServerAndClient
HttpCacheability.ServerAndPrivate
Host server on which request is processed and client on which request originated.