Tuesday, December 13, 2005 5:45 PM
DmitryR
Disk Output Cache
Please check out my latest project -- an HTTP Module that implements Disk Output Cache for ASP.NET v2.0.
The package includes binaries as well as the complete sources for the module. Download from the attachment to this blog entry.
Note: Beta releases of ASP.NET v2.0 included a disk output cache feature that did not make it into the final product. The code for this disk output cache module is not based on the feature from ASP.NET beta releases, it just fills in the gap by implementing a similar functionality.
Goals of Disk Output Cache.
There are two main scenarios (both unsupported by the regular memory-based output cache in ASP.NET) that disk output cache for ASP.NET pages is attempting to address:
- Preservation of cached output across app domain and process restarts. Memory-based output cache only holds on to the responses while the app domain is alive, thus all responses must be re-created after the app domain shuts down. Disk output cache will serve cached response after app domain (or the worker process) is re-started. Thus disk output cache should be helpful when responses could be cached for a long time and are expensive to re-recreate.
- Avoiding using memory for cached responses. Disk output cache [by default] uses Response.TransmitFile API to send the response directly from disk, thus reducing the memory use, especially when cached responses are large and there are many of them, as in vary-by cases.
Feature Details
- Disk output cache is implemented as an HTTP module that can be installed either in GAC or in bin directory of a web application.
- Response expiration is time-based. In addition, disk output cache automatically detects when a page gets recompiled and invalidates all cached responses for the page.
- The feature supports “vary-by” caching based on the query string.
- The implementation is only using public System.Web APIs. Output capturing is implemented via HttpResponse.Filter. There are no public APIs to access the cache policy, thus configuration is used instead.
- Disk output cache is driven by configuration. Configuration specifies the cache location, the list of requests that need to be cached and for how long, scavanging policy, etc. The disk output cache configuration section is implemented using SCDL.
This is the very first release of disk output cache, so there could be some bugs. Please let me know if you run into something.