ASP.NET 4 adds an extensibility point to output caching that
now enables developers to configure one or more custom output-cache providers.
Output-cache providers can use any storage mechanism to persist output cached
content. This makes it possible to easily create output-cache providers that
store the cached content using any persistence mechanism – including local or
remote disks, databases, cloud storage, and distributed cache engines (like
memcached or velocity).
You can create a custom output-cache provider by creating a
class that derives from the new System.Web.Caching.OutputCacheProvider class in
ASP.NET 4. Within your derived class you then override 4 public methods
that provide implementations for adding/removing/retrieving/updating cached
content (a unique key is passed to identify each separate cached entry).
You can then configure ASP.NET 4 to use your custom outputcache provider by
registering it using the new <providers> subsection of the
<outputCache> element within an application’s web.config file:

Above I’ve added a new output cache provider
(which I’ve named “SampleCache”) that is implemented using the
“ScottOutputCache” class within my OutputCacheSample.dll assembly. I’ve
also configured ASP.NET to use my “SampleCache” implementation as the default
output cache implementation whenever content is output cached – this is done by
setting the “defaultProvider” attribute on the <outputCache>
element.
And now, when I add an OutputCache directive
to the top of any of .aspx page the content will be cached and stored using my
ScottOutputCache provider:
<%@ OutputCache Duration="60"
VaryByParam="None" %>
Likewise, if I add an [OutputCache] attribute
on any action method within an ASP.NET MVC Controller the content will also be
cached and stored using my ScottOutputCache provider:
