One of the most sure-fire ways to improve a web application’s performance is to employ caching. Caching takes some expensive operation and stores its results in a quickly accessible location. Since it’s inception, ASP.NET has offered two flavors of caching:
- Output Caching – caches the entire rendered markup of an ASP.NET page or User Control for a specified duration.
- Data Caching – a API for caching objects. Using the data cache you can write code to add, remove, and retrieve items from the cache.
Until recently, the underlying functionality of these two caching mechanisms was fixed – both cached data in the web server’s memory. This has its drawbacks. In some cases, developers may want to save output cache content to disk. When using the data cache you may want to cache items to the cloud or to a distributed caching architecture like memcached. The good news is that with ASP.NET 4 and the .NET Framework 4, the output caching and data caching options are now much more extensible. Both caching features are now based upon the provider model, meaning that you can create your own output cache and datacache providers (or download and use a third-party or open source provider) and plug them into a new or existing ASP.NET 4 application.
This article focuses on extending the output caching feature. We’ll walk through how to create a custom output cache provider that caches a page or User Control’s rendered output to disk (as opposed to memory) and then see how to plug the provider into an ASP.NET application. A complete working example, available in both VB and C#, is available for download at the end of this ASP.NET tutorial. Read the entire article, Extending ASP.NET Output Caching by clicking here.