ASP.NET 4.0 Core Services

Your Ad Here

Core Services
ASP.NET 4 introduces a number of features that improve core ASP.NET services

* output caching
* session-state storage

Extensible Output Caching
ASP.NET 4.0 allows you to configure one or more custom output-cache providers.
Output-cache providers can use any storage mechanism to persist HTML content.
like local or remote disks, cloud storage, and distributed cache engines.

You can create a custom output-cache provider as a class that derives from the new System.Web.Caching.OutputCacheProvider type.
You can then configure the provider in the web.config file by using the new providers subsection of the outputCache element, as shown in the following example:

public class CustomInitialization : System.Web.Hosting.IProcessHostPreloadClient
{
public void Preload(string[] parameters)
{
// Perform initialization.
}
}

By default in ASP.NET 4.0, all
HTTP responses,
rendered pages, and
controls
use in-memory output cache

You can also select different
output-cache providers
per
control and
per request.

You can use a providerName attribute in a page or control directive, as shown in the following example:
<%@ OutputCache Duration="60" VaryByParam="None" providerName="DiskCache" %>

Specifying a different output cache provider for an HTTP request requires a little more work. Instead of declaratively specifying the provider, you instead override the new GetOuputCacheProviderName method in the Global.asax file to programmatically specify which provider to use for a specific request. The following example shows how to do this.

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

Now it is possible to cache the "Top 10" pages of a site in memory, while caching pages that get lower traffic on disk. Alternatively, you can cache every vary-by combination for a rendered page, but use a distributed cache so that the memory consumption is offloaded from front-end Web servers.

Subscribe
Posted in Labels: kick it on DotNetKicks.com |

0 comments: