ASP.NET

Conclusion: Cache output

Caching is a tried and true way to improve the performance of almost any system. By making frequently used content available quickly through the output cache, you can speed up the perceived performance of your application by a wide margin.

Turning on output caching in ASP.NET is a matter of including the correct directive at the top of your page. Naive use of the cache involves simply placing it on the page code and setting the Duration to some number and the VaryByParam attribute to none. However, you may also control various behaviors of the output cache by setting variables within the OutputCache directive. You may also control output caching behaviors through the HttpCachePolicy class, available through the Cache property of the Response object. ASP.NET supports cache profiles so you don't have to hard-code the caching parameters into the OutputDirective.

User Controls often represent a prime output caching opportunity-especially if they're navigation controls or some other control that doesn't change very often. By applying the OutputCache directive to the User Control, ASP.NET caches that part of the page on which it was placed.

Tutorial 15 Quick Reference

How to cache a page's output

Add the OutputCache directive to the page


How to store multiple versions of a page based on varying query string parameters

Use the VaryByParam attribute of the OutputCache directive


How to store multiple versions of a page based on varying headers

Use the VaryByHeader attribute of the OutputCache directive


How to store multiple versions of a page based on varying browsers

Use the VaryByCustom attribute of the OutputCache directive, selecting "browser" as the value


How to specify the location of the cached content

Specify the Location attribute in the OutputCache directive


How to access caching attributes programmatically

Use the Cache property of the Response object, which is an instance of the HttpCachePolicy class


How to offload output caching configuration to the Web.Config file

Add outputCacheProfile elements to your Web.Config file. Use them as necessary


How to cache a User Control

Apply the OutputCache directive to the control's ASCX file