Techbubbles

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: http://WWW.ASP.NET white paper on ASP.NET 4.0

Share this post :


Related Posts:

  • No Related Posts
  • http://aokocax.net Oğuz KOCA

    Hi,thanks for share. I think You should add bookmark button on your entries (digg it, kick it, dzone etc.) And what is the direct link of white paper?

  • Pingback: Web Forms model in ASP.NET 4.0 | TechBubbles

  • Merry

    Why don’t you try some distributed .NET caching solution? In my opinion, it’s better to have distributed cache instead of local cache. There are a lot of distributed .NET caching solutions available there in the market and doing very good job. There are some .NET distributed caching products which are available for free as well like NCache Express.

    http://www.alachisoft.com/ncachepoint/ncachepoint_express.html

%d bloggers like this: