Cache is a very important feature when you think about end user response time and also server load. In my case, I was tweaking the configuration for a internet public sites in order the have a better user experience.
To improve the end user response time a good approach is to configure the BLOB Cache on the SharePoint 2010 Web Front End (WFE) servers. The BLOB cache caches files on the WFEs disk to make it faster for IIS to retrieve the files and return them to the browser. It can also send some HTTP headers telling the browser to cache the file for a certain amount of time.
We need to change the web.config to enable the BLOB cache. Find the BlobCache tag on the configuration/SharePoint node on the web.config. Here is an example of a configured Blob Cache:
<BlobCache location=”C:\BlobCache\14″ path=”\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv)$” maxSize=”10″ enabled=”true” max-age=”36000″ />
The location attribute defines where SharePoint is going to save the cached files.
The path attribute represents a regex defining the file extensions to be cached.
The maxSize attribute defines the maximum size of the cache in Giga bytes.
The enabled attribute defines if the cache is enabled.
The max-age attribute defines the maximum time in seconds the browsers can cache the files locally and avoid making requests for these file to the server. This setting affect how the users’ browser cache the files defined on the path attribute.
Another cache feature available on SharePoint 2010 is the Output Cache.
The Output Cache caches the HTML output for the pages processed by SharePoint. This cache improves the server processing time for the cache pages since IIS doesn’t need to call SharePoint and wait for the page to be processed. It just gets the cached copy and send the HTML back to the browser. The Output Cache is configured per Site Collection.
First we need to make sure the cache profile is configured in the way we need.
Go to the Site Settings page, then to Site Collection Administration and then to Site Collection Cache Profiles.
The default cache profiles are listed. I’ll check if the Public Internet one is alright for my needs.
In my case I’ll need a few tweaks on the cache profile configuration:
- Check for changes: This setting needs to be Yes in order for the cache to items in the cache if they changed before the duration of the cache. It affects performance but it is a good option to make sure Content Managers have their content showing up on the site as soon as they approve it.
- Vary by query string parameters: Since we have several dynamic pages which receive parameters by query string and produce different HTML in the output we need to specify the query string parameter. The value of the parameter should be * since the names of the parameters vary a lot.
My new cache profile looks like this:
After your cache profile is ready, you should go to the Site Settings page, then to Site Collection Administration and then to Site Collection Output Cache.
Make sure you enable the Output Cache and select the cache profile you just created.
Now you just need to recycle your app pools and start testing the cache. Both caches can be tested in HTTP monitoring tools such as Fiddler, HTTP Watch, IE Developer Tools or Chrome Developer Tools.
Two important notes on testing:
- If you hit F5 on a page, your browser will sent HTTP headers to the server telling it to ignore any cache. The best way to test is navigating thru the site and checking which page and assets (images, js, css files) are called or cached.
- If you configure your browser to always request the most current version of the page, the BLOB cache will not work on the client side.
More references about caching can be found at:
SharePoint BlobCache Explained
Digging Deeper into the 2010 Caching Options: Part 1
Digging Deeper into the 2010 Caching Options: Part 2
Client-Server Interactions and the max-age Attribute with SharePoint BLOB Caching
BLOB Cache, HTTP 304 Results and F5/Refresh