TechBubbles Microsoft Technology BLOG

ASP.NET 4.0 Extensible Output Caching

A number of Exciting ASP.NET features are coming in the .NET Framework version 4.0. These features are included in Visual Studio 2010 release. This post explains about one of those features core services in ASP.NET 4.0

                                             image-thumb

Extensible Output Caching

Output Caching enables the developers to store the HTTP response and page output in memory. Using Output Caching Feature ASP.NET can serve the subsequent requests more quickly by retrieving the data from memory. The limitation for this approach is It has to store the content always in memory

ASP.NET 4.0 having an extensibility option for output caching by configuring custom output-cache providers.  Output-cache providers can use any storage mechanism to persist HTML content. These can include local or remote disks, cloud storage and distributed cache engines.

<caching>
  <outputCache defaultProvider="AspNetInternalProvider">
    <providers>
      <add name="DiskCache" 
          type="Test.OutputCacheEx.DiskOutputCacheProvider, DiskCacheProvider"/>
    </providers>
  </outputCache> 
</caching>

The default configuration settings for output-cache are as shown above.

You can create a custom output-cache provider as a class which derives from System.Web.Caching.OutputCacheProvider type.

You can also select different output-cache per control or per request. You can declaratively set the providerName attribute in a page or control directive as shown below.

<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>

After specifying the provider name in page directives then you also need to override a method in the Global.asax file to programmatically specify which provider to use for a specific request.

public override string GetOutputCacheProviderName(HttpContext context)
{
    if (context.Request.Path.EndsWith("Advanced.aspx"))
       return "DiskCache";
    else
        return base.GetOutputCacheProviderName(context);
}

With this addition of output-cache feature to ASP.NET 4.0, you can now use this strategy for your websites.

Eg: The more traffic that you get for the pages in the website can use the in memory caching and the less traffic getting pages can use the disk cache.

Recommended option is using distributed cache so that the memory consumption is offloaded from front-end web servers.

Source: WWW.ASP.NET white paper on ASP.NET 4.0

Share this post :

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

3 Comments

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud