Output Caching and Cache Profiles

Microsoft Office SharePoint Server 2007 uses output caching technology native to ASP.NET 2.0 to manage when and how page content is served. ASP.NET output caching is the foundation of the Office SharePoint Server 2007 caching functionality; consequently, output caching in Office SharePoint Server 2007 behaves similarly to output caching technology available in ASP.NET 2.0.

On a heavily accessed Office SharePoint Server 2007 site, caching frequently accessed pages for even a minute at a time can result in substantial throughput gains. While a page is cached by the output cache, subsequent requests for that page are served from the output page without executing the code that created it for the specified duration of the cache.

Pros and Cons of Output Caching

Before choosing to use output caching to improve the performance of page and page-item rendering, consider benefits and drawbacks of a potential output caching implementation. All considerations are not listed in this document, but some benefits you may want to consider include:

  • Each equivalent class of content (such as page or item within a page) receives faster response, and therefore shorter latency, after it is initially rendered.

  • Each server uses less CPU time and energy to serve the same page after the initial rendering.

  • Each data source for the rendered page can scale to serve more Web clients because of the decreased traffic flow that output caching makes possible.

  • For each page request for which an output cached version of a page is served, the server does not have to:

    • Make a round trip to the database to fetch the source code for the .aspx page and any .ascx controls on the page.

    • Reload and re-render the controls.

    • Requery any data sources that the controls rely on for data.

However, before deciding to implement output caching, you may want to consider the following concerns:

  • Output caching consumes additional memory. Each version of a page consumes memory on the Web client.

  • When used with two or more front-end Web servers, output caching may affect consistency. You can configure a cache profile not to check for updates for each request and, for example, instruct it to ignore changes to the version of the Web page in the output cache until 60 seconds after the original page is updated. If you have two front-end Web servers in your topology, and depending on the load balancer used to route the user's request, a reader of site content could see inconsistency if the page is rendered by one server and then a subsequent request is routed to a second server within that 60-second window.

Cache Profiles

Office SharePoint Server 2007 adds a more precise mechanism for customizing output caching than those available natively in ASP.NET 2.0. Office SharePoint Server 2007 includes cache profiles, which are list-style cache settings that you can name and apply to pages, page items, content types, and levels of scale in your site deployment.

By using cache profiles, you can control the level of granularity applied to output caching; allow or disallow site owners and administrators to choose their own cache profiles and apply them flexibly to page layouts; and target output caching at the site collection, site, and page layout levels.

You can organize caching behavior based on a user's access rights to a site. For example, you may have three groups defined: one with full control, one with read and write rights, and one with read-only rights. Output caching renders the page the same way for users with the same rights, so you can use cache profiles to target caching to specific audience groups. In the cache profiles that Office SharePoint Server 2007 delivers by default, the caching system renders the page once per group of user access rights and then caches the resulting HTML stream. The next user with the same access rights gets the stream from the cache.

After you create and deploy a cache profile, any change to the cache profile immediately affects all applicable content on the site. For example, if all document library page layouts in a given site collection are initially cached for 60 seconds, and you increase that duration to 120 seconds, every document library page layout in that site collection is cached for 120 seconds regardless of the number of document library page layouts or sites in the site collection.

You can define a cache profile by using the cache profile stored in a standard Office SharePoint Server 2007 list, and extend it programmatically by using a VaryByCustom handler. If you apply the cache profile to the site and page layout through the user interface, down-level propagation enforces consistency in child sites. Cache policy is secured independently from other Office SharePoint Server 2007 features.

NoteNote:

To learn more about creating cache profiles in this way, see How to: Extend Caching by Using the VaryByCustom Event Handler. It describes how to create a VaryByCustom event handler, how to modify a cache profile to include custom string parameters that are passed to VaryByCustom, and how add required code to the global.asax file.

Procedures

To enable output caching for a site collection

  1. Navigate to the root Web site of the site collection. On the Site Actions menu, click Site Settings.

  2. In the Site Collection Administration section, select Site collection output cache.

  3. To enable output caching for this site collection, select Enable output cache.

  4. Choose a cache profile for anonymous users from the Anonymous Cache Profile list. This profile is applied when anonymous users access a site in this site collection.

  5. Choose a cache profile for authenticated users from the Authenticated Cache Profile list. This profile is applied when authenticated users access a site in this site collection.

  6. Choose Page Output Cache Policy options.

    • If publishing sites can use a different output cache profile, select Publishing sites can use a different page output cache profile.

    • If page layouts can use a different output cache profile, select Page layouts can use a different page output cache profile.

  7. If you want to display additional cache information on pages in this site collection, including the date and time that page contents were last rendered, select Enable debug cache information on pages.

  8. Click OK.

To enable output caching for a site

  1. Navigate to the root Web site of the site collection. On the Site Actions menu, click Site Settings.

  2. In the Site Administration section, select Site output cache.

  3. Choose an Anonymous Cache Profile option:

    • If you want to inherit a cache profile, click Inherit the profile.

    • If you want to choose a cache profile from those currently available, select Select a page output cache profile.

  4. If you want to apply these settings to all subsites of this root Web site, select Apply these settings to all sub-sites.

  5. Click OK.

To create a new cache profile

  1. Navigate to the root Web site of the site collection. On the Site Actions menu, click Site Settings.

  2. In the Site Collection Administration section, select Site collection cache profiles.

  3. Click New.

  4. Define and create a new cache profile.

    Detail Description

    Title

    Required. The system name of this cache profile.

    Display Name

    Populates the list of available cache profiles for site owners and page layout owners.

    Display Description

    Populates the list of available cache profiles for site owners and page layout owners.

    Perform ACL Check

    Select to ensure that all items in the cache are security trimmed.

    Enabled

    Select if you want caching to happen.

    Duration

    Number of seconds to keep the cached version available.

    Check for Changes

    Select to validate on each page request that the site has not changed and to flush the cache when the site changes.

    Clear if you want better performance. If unchecked, system does not check for updates to sites for the number of seconds specified in Duration.

    Vary by Custom Parameter

    Specify a value as described in the ASP.NET 2.0 HttpCachePolicy.SetVaryByCustom method documentation.

    Vary by HTTP Header

    Specify a value as described in the ASP.NET 2.0 HttpCachePolicy.VaryByHeaders property documentation.

    Vary by Query String Parameters

    Specify a value as described in the ASP.NET 2.0 HttpCachePolicy.VaryByParams property documentation.

    Vary by User Rights

    Select to ensure that users must have identical effective rights on all SharePoint security scopes to see the same cached page as any other user.

    Cacheability

    Choose a value from the drop-down list. Choices include NoCache, Private, Server, ServerAndNoCache, Public, and ServerAndPrivate. To learn more, see the ASP.NET 2.0 HttpCacheability enumeration topic.

    Safe for Authenticated Use

    Select only for policies that you want to allow administrators and page layout designers to apply to authenticated scenarios.

    Allow writers to view cached content

    Select to bypass the default behavior of not allowing people with edit rights to cached their pages.

See Also

Community Additions

ADD
Show: