ASP.NET page output caching is the feature that allows you to cache page responses so that successive requests can be satisfied without reexecuting the page, but simply by returning the cached output. Page caching is smart enough to let you save distinct output based on the requesting URL, query string, or form parameters.
When ASP.NET runs under IIS 6.0, the web server may optionally intervene and serve previously cached pages before ASP.NET kicks in. When integrated in the web server, the output caching mechanism provides much better performance and responsiveness.
IIS can cache a copy of the page output and serve it again through the http.sys kernel-level driver. The output caching facility in IIS 6.0 has been used by ASP.NET since Version 1.1 to host the output cache. So, when using the output cache directive in ASP.NET 1.1 and ASP.NET 2.0 applications, most of your responses are being served from the kernel cache. This form of integration will continue and get even stronger with the advent of the next version of IIS.
It is important to note that page output caching works only for anonymous content. Requests for cached pages served by IIS 6.0 never reach stages in the ASP.NET pipeline where they can be authenticated. The output caching feature, especially if implemented at the kernel level, has tremendous potential and can dramatically improve the performance of a web server, as long as enough of the content being served is cacheable. What's the performance gain you can get?
According to the numbers provided with the IIS 6.0 technical documentation, an application using the kernel cache returns a throughput of over 10 times the throughput you would get in the noncached case. Additionally, the latency of responses is significantly better. To get more information and comparable tables, go to http://www.microsoft.com/technet/prodtechnol/ windowsserver2003/technologies/webapp/iis/iis6perf.mspx.
In particular, the parameters that indicate the number of requests served per second and time-to-last-byte are dramatically better; most of the CPU utilization is in kernel mode and a larger number of context switches per second occur when output caching is integrated in IIS 6.0.
To enable an ASP.NET page for output caching, you have to decorate it with the @OutputCache directive. The great news for developers, though, is that, aside from this, no other code changes are required to benefit from kernel caching. There's something more to know about kernel caching, though. While kernel caching can really boost the performance of a high-volume web site, some limitations apply. First and foremost, kernel caching is available only for pages requested through a GET verb. No kernel caching is possible on postbacks and POST requests in general. Furthermore, pages with VaryByParam and VaryByHeader attributes set are also not stored in the kernel cache. Finally, note that ASP.NET Request/Cache performance counters will not be updated for pages served by the kernel cache.
When kernel caching is impossible, ASP.NET tries its best and caches page responses internally in the Cache object. In this case, the limitations you observe with kernel caching (such as POST requests) disappear, but the performance is worse. All in all, though, for relatively static pages that do not require clicking, even a one second cache may be a great improvement.
Dino Esposito is Wintellect's ADO.NET and XML expert, and a trainer and consultant
based in Rome, Italy. Dino is a contributing editor to Windows Developer
Network and MSDN Magazine, and the author of several books for Microsoft
Press including Building Web Solutions with ASP.NET and ADO.NET
and Applied XML Programming for .NET. Contact Dino at email@example.com.