Click to Rate and Give Feedback
MSDN
MSDN Library
SDK Documentation
 How to: Enable ASP.NET Output Cachi...
Microsoft Content Management Server 2002 SDK
How to: Enable ASP.NET Output Caching

You enable Microsoft ASP.NET output caching at the page level or at the user control level by adding the OutputCache directive to either a Microsoft Content Management Server (MCMS) 2002 template file or to a user control in an MCMS Web application.

  • To ensure that each posting based on an MCMS template is cached separately, you specify the VaryByCustom attribute as CMSPosting.

  • To ensure that each user control used on an MCMS template is cached separately for each posting based on the template, you specify the VaryByCustom attribute as CMSPosting;CMSControl.

  • If the user control is the same for all postings based on all templates, you specify the VaryByCustom attribute as CMSControl.

For more information about the OutputCache directive, see the ASP.NET documentation.

To enable output caching on a template file

  1. Change your MCMS Web application to inherit from CmsHttpApplication by changing the inheritance syntax of the Global class in the global.asax.cs file to the following.

    public class Global : CmsHttpApplication
  2. Add the following OutputCache directive to the template file.

    <%@ OutputCache Duration="300" Location="Server" VaryByParam="None" 
    VaryByCustom="CMSPosting" %>

To enable output caching on a user control

  1. Change your MCMS Web application to inherit from CmsHttpApplication by changing the inheritance syntax of the Global class in the global.asax.cs file to the following:

    public class Global : CmsHttpApplication
  2. Add the following OutputCache directive to the user control file.

    <%@ OutputCache Duration="300" VaryByParam="None" 
    VaryByCustom="CMSPosting;CMSControl" %>

Enabling cache invalidation can have a detrimental effect on the performance of your Web site. Each posting contains a call to the validation method, which adds to the time it takes to serve the posting. In addition, when a content change occurs on the Web site, the entire cache is invalidated.

NoteNote:

ASP.NET output cache invalidation cannot be used on user controls.

An alternative to enabling cache invalidation is to set the duration of the cache to a short period of time. The duration is the longest time that cache serves a posting before it is re-requested from the Content Repository. By setting the cache Duration attribute to 300 (five minutes), you can ensure that content served on the Web site is never more than five minutes out of date. For more information, see the procedure "To enable output caching on a template file" earlier in this topic.

To add cache invalidation to a template file

  1. Enable ASP.NET output caching on the template file. For more information, see "To enable output caching on a template file" earlier in this topic.

  2. Add the following code to the Page_Load method of the code-behind page of the template file.

    CmsHttpCachePolicy.Current.AddValidationCallbackAllCmsHierarchyItems();

If your templates contain personalization, such as a display of users' names, you must change your output caching directive so that it only caches a template or user control with the correct user's personalized information. To ensure that the cache contains an item for each user or user role, you specify the VaryByCustom attribute as CMSUser or CMSRole. These MCMS keywords tell the cache to cache the content separately for each MCMS user or MCMS user role.

To enable output caching on a user control that has user-based personalization

  1. Change your MCMS Web application to inherit from CmsHttpApplication by changing the inheritance syntax of the Global class in the global.asax.cs file to the following.

    public class Global : CmsHttpApplication
  2. Add the following OutputCache directive to the user control file.

    <%@ OutputCache Duration="300" VaryByParam="None" VaryByCustom="CMSPosting;CMSControl;CMSUser"%>

To enable output caching for a template file that has role-based personalization

  1. Change your MCMS Web application to inherit from CmsHttpApplication by changing the inheritance syntax of the Global class in the global.asax.cs file to the following.

    public class Global : CmsHttpApplication
  2. Add the following OutputCache directive to the template file.

    <%@ OutputCache Duration="300" Location="Server" VaryByParam="None"
     VaryByCustom="CMSPosting;CMSRole" %>

If you are using Microsoft Internet Security and Acceleration (ISA) Server to maintain a centralized cache for your MCMS Web site, then when you enable ASP.NET output caching, you specify the Location attribute of the OutputCache directive as Downstream. This enables ISA Server to cache the content instead of requiring it to be cached on the MCMS server. For more information about ISA Server, see the ISA Server documentation.

To enable output caching for a template file if you are using ISA Server

  1. Change your MCMS Web application to inherit from CmsHttpApplication by changing the inheritance syntax of the Global class in the global.asax.cs file to the following.

    public class Global : CmsHttpApplication
  2. Add the following OutputCache directive to a template file.

    <@ OutputCache Duration="300" Location="Downstream" 
    VaryByParam="None" VaryByCustom="CMSPosting" >

To enable output caching for a user control if you are using ISA Server

  1. Change your MCMS Web application to inherit from CmsHttpApplication by changing the inheritance syntax of the Global class in the global.asax.cs file to the following.

    public class Global : CmsHttpApplication
  2. Add the following OutputCache directive to the user control file.

    <@ OutputCache Duration="300" VaryByParam="None" VaryByCustom="CMSPosting;CMSControl" >

See Also

© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker