| |||||||||||||
Setting the Output Cache LocationASP.NET Web Applications ASP .NET Caching Features You can set the cacheability of page or user control output by using the Location attribute of the @ OutputCache directive, or by specifying HttpCacheability enumeration values in the page's Response.Cache property ( HttpResponse.Cache ). Either of these techniques set the Cache-Control HTTP header for a response.
The default value for the Location attribute is Any, which allows the page output to be cached on all cache-capable network applications that are involved in the response. This includes the requesting client, the responding server, or a proxy server through which the response passes. This default behavior is equivalent to the following code.
You may need to change these default settings, depending on the needs of your page or application. For example, if a page requires authentication and you want to cache its output, change the Cache-Control header to private. The following @ OutputCache directive declared at the top of the page does this, and also sets the amount of time that the page is cached to 60 seconds. <%@ OutputCache Duration=60 Location = "Client" %> You would have to apply the following code in your page or application to achieve the same result. Response.Cache.SetExpires ( DateTime.Now.AddSeconds ( 60 ) ); Response.Cache.SetCacheability ( HttpCacheability.Private ); The @ OutputCache directive is much simpler than the code that it automatically calls when you use it. To enable caching only on cache-capable applications in the request stream between the client and the Web server, such as a proxy server, set the Location attribute to Downstream. This sets the cacheability of the page output to Public, but uses the SetNoServerCaching method to disallow caching the page output on the Web server. For example, including
You can also specify that a page's output is cached only on the server by setting the Location attribute to Server. This disables client and downstream caching, ensures that the origin server controls the cacheability of the output, and also ensures that all clients must request the document from the server. All requests for the document are served from the server cache for the specified duration. You can also disable output caching for the page entirely by setting the Location attribute to None. This is the equivalent of using the HttpCacheability.NoCache field.
See AlsoCaching ASP.NET Pages @ OutputCache Directive |
| ||||||||||||
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note