Monday, January 12, 2015

SharePoint 2013: how to implement basic web application caching to improve performance


Implementing caching can substantially improve page performance. There are fundamentally two kinds: browser-based and server-based.  Browser-based involves the user's browser storing pages and page components (eg, js files, image files, applets, etc) on the user's workstation.  Server-based can involve a variety of different components including: proxy servers, caching servers (eg, AppFabric AKA Distributed Caching), and application-based, such as SharePoint caching methods.  This posting focuses on implementing SharePoint-based caching methods useful in common SharePoint 2013 intranet deployment scenarios.

There are three SharePoint-based caching methods that can be implemented: binary large object (BLOB) caching, page output caching and object caching.  All of these have been available since at least 2007.  There is a fourth kind of SharePoint-based caching, anonymous search results caching, but that won't be discussed here.  BLOB caching involves the web server storing locally on disk those dependent files used by web pages so as to reduce database requests and thereby reducing processing and improving responsiveness.  Page output caching is based upon ASP.NET caching.  It involves the caching of web pages and even versions of those web pages so as to be able to immediately return a page to the user when it matches the user's request, thereby greatly improving responsiveness; it can be configured at the web application, site collection, site and page levels.  Lastly, object caching involves the caching of page objects, i.e., lists, settings, page layouts, libraries, etc.  Object caching can respond to page requests even when those requests involve different pages, but the same objects.

By default, the BLOB and page output caching are disabled on new deployment and must be enabled manually.  Object caching is enabled at the site collection level on new deployment, after activating the Publishing feature.  Enabling BLOB caching involves a simple edit of each web front end server's Web.Config file, and the same change must be implemented in each file.  Enabling page output and object caching involves activating the Publishing feature. This posting walks through implementing each of these cache types.

  1. BLOB Caching
    1. Login to a farm web front end server.
    2. Launch IIS
    3. In the left Connections panel, expand the Sites node so that your website is shown.
    4. Right-click your website, and then select Explore.
    5. Make a copy of the Web.Config file.
    6. Open the Web.Config file in Notepad.
    7. Search for the tag <BlobCache.
    8. Set the location attribute to the path you want on your server. 
      This path should be the same for all web front end servers.
    9. Set the maxSize attribute as desired.  The units here are in GB.  This should be no lower than 10.
    10. Set the enabled attribute to true.
    11. Save and close the file.  The change
      Modification of the web.config file immediately triggers a recycle of the web application, which may result in some user data loss. 
    12. Repeat for each web front end server.  The modifications to the web.config file must be identical for each.
      Any modification to the web.config file immediately precipitates an IIS reset.
  2. Page Output Caching
    1. Activate Publishing (skip if already done)
      1. Login to a farm web front end server.
      2. Navigate to: Site Collection > Site Settings > Site Collection Administrator > Site collection features.
      3. Activate SharePoint Server Publishing Infrastructure
      4. Now navigate to: Site Collection > Site Settings > Site Actions > Manage site features.
      5. Activate SharePoint Server Publishing.
    2. Set for entire web application
      1. Launch IIS Manager
      2. In the left-hand Connection panel, expand the server node and then expand the Sites node.
      3. Right-click on the target web application, and then select Explore. 
      4. Make a copy of the web.config file.
      5. Open the original in Notepad.
      6. Set WFE1 Web.config: <OutputCacheProfiles useCacheProfileOverrides="true"…
      7. Set WFE2 Web.config: <OutputCacheProfiles useCacheProfileOverrides="true"…
      8. Save the file.
    3. Set for a site collection
      1. Navigate to: Site Collection > Site Settings > Site Collection Administration > Site collection output cache.
      2. Check the Enable output cache checkbox.
      3. Select the appropriate Anonymous and Authenticated profiles.  For example, for a departmental farm situated on the corporate intranet, select Disabled for Anonymous and Intranet for Authenticated. 
        You are not restricted to these profiles.  You can customize these are create new ones by navigating to: Site Collection > Site Settings > Site Collection Administration > Site collection cache profiles.  Listed here are the four default profiles, and you can create new ones.
      4. If your farm employs both Publishing and non-publishing sites, it might be useful to distinguish among them - testing will be needed to determine this.  Similarly, being able to configure page output caching by page layout can be useful when one or more layouts are used for specific high-volume data needs, such as search results pages.
      5. Click OK.
    4. Set for a site
      1. Navigate to: Site Collection > Site Settings > Site Administration > Site output cache.
      2. Here you have the option of configuring site caching to inherit the caching configuration of the parent site collection or specifying unique caching configuration.
      3. Select as desired, and then click OK.
    5. Set for a page
      1. Navigate to: Site Collection > Site Settings > Site Administration > Site collection output cache.
      2. Enter a check into the Page layouts can use a different page output cache profile setting.
      3. Click OK.
      4. Navigate to: Site Collection > Site Settings > Web Designer Galleries > Master pages and page layouts.
      5. Check or select the layout file you want to configure.
      6. On the ribbon, select the FILES tab.
      7. On the FILES tab, in the Manage group, click Edit Properties.  You will also need to check out this file in order to edit its properties.
      8. Configure as desired, and then click OK.
  3. Page Object Caching
    1. Navigate to: Site Collection > Site Settings > Site Collection Administration > Site collection object cache.
    2. Configured as desired, and then click OK.
  • Implementing caching for My Sites presents some minor challenges.  The reason being that every user's My Site is a unique site collection.
  • I was not able to find much MS SharePoint 2013 documentation on caching whilst exploring the SharePoint documentation tree.  I was able to find much more detailed articles on caching in the 2007 documentation tree. 
  • Microsoft's discussion on enabling object caching in SharePoint 2013 only presents how to configure this by editing the web.config file.  However, you can still configure object caching through site collection administration settings, as discussed above and in the Microsoft article for object caching SharePoint 2007.

No comments: