17 August, 2011

Configuring Caching for an Entire Application in Asp.net

You can configure output caching profiles that you can easily reference from pages in your
application. This provides centralized configuration of output caching. To create a cache
profile, add the caching,outputcachesettings,outputcacheprofiles section to your
Web.config file’s element, as the following sample demonstrates.









Caching profiles support most of the same attributes as the @ OutputCache directive,
including Duration, VaryByParameter, VaryByHeader, VaryByCustom, VaryByControl,
SqlDependency, NoStore, and Location. Additionally, you must provide a Name attribute
to identify the profile, and you can use the Enabled attribute to disable a profile if necessary.

After you create a cache profile, reference it from within a page by using the CacheProfile
attribute of the @ OutputCache directive, as the following example demonstrates. You can
override specific attributes on a per-page basis.

<%@ OutputCache CacheProfile="OneMinuteProfile" VaryByParam="none" %>

No comments:

Post a Comment