.NET FAQs Unleashed!
 
    
    

What is the benefit of Extensible Output Caching in ASP.NET 4.0?

Cache object is stored on the Web Server. Extensible Output Caching empowers you to store your cache objects on other machines such as other local disks, remote disks and cloud storage locations.

Benefit: You can now decide what to be cached on your busy Web Server, and what to cache on other locations.

How to do it?
1. Create a class that derives from the new System.Web.Caching.OutputCacheProvider
2. Set the following in the web.config file, under the new providers sub section:

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

3. Set the following for the control:

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

4. Set the following per request:
This is to be added in global.asax

C# Example:

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

Extensible Output Caching allows to intelligently identifying which components of a web page should be cached. For example, you can decide to cache the top five pages of your website.

ASP.NET 4 when IIS is reset   Meta Tags using the Page Directives   Response.Redirect(), Response.RedirectPermanent(), Server.Transfer()   Shrinking Session State   Expanding size of allowable URL   Preventing XSS Attacks in ASP.NET 4   New features in ASP.NET 4.0   Features of ASP.NET 4.0 Chart Control   Advantage of Response.RedirectPermanent()   Benefit of Extensible Output Caching   URL Routing   Web.config Refactoring   Controlling IDs of Controls   Monitor Performance in ASP.NET 4.0