SharePoint 2013 Hosting :: SharePoint BLOB Cache (Disk Based Caching) fundamentals

What is blob cache?

Blob Cache is a disk based caching mechanism for Binary Large Objects (BLOBs) which can be used with SharePoint sites to decrease response times for pages within a SharePoint site. It also helps reduce database load on SQL servers and network traffic between SharePoint and SQL servers. Binary Large Objects (BLOBs) such as images, videos and audio files, large code files are retrieved from the database and can be cached and stored in a directory on the web front end server(s). Thus, when a user requests for a page/file, SharePoint server can respond faster by returning the file from the server cache rather than making a round trip and retrieving the data from SQL server every time. BLOB caching can be enabled on Web Front End (WFE) servers.

ahp-new-banner

In SharePoint 2010, new the concept of byte-range requests is introduced which allows a user to select a later point in the video and being playback from that point. SharePoint also provides the concept of progressive caching, which starts streaming the video from the beginning of the large video file and the rest of the file is cached. Video files are also divided and retrieved in smaller sections to reduce load between the WFE and SQL servers. Administrators have the option to configured the size of these file sections.

BLOB caching is mostly used in Internet facing (anonymous access) or with sites which have read-only documents (which are not modified on regular basis) and static content. We can specify the files e.g. documents, images, etc to be cached on the server so that the response time decreases.

BLOB cache is usually stored in a directory on the web front end servers on the drive where SharePoint is installed. We need to ensure that the drive has sufficient space where the files will be stored. The location of BLOB cache can be set as per our requirement.
To enable BLOB cache on WFE servers, we need to configure the web.config file for the web applications. By default, disk based BLOB caching is turned off and must be enabled on front end web servers. In the web.config file of the web application, we will see a code line as

<BlobCache location=”” 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=”false” />

In this line, change the enabled attribute from “false” to “true”. If needed specify the location where the files need to be stored and the type of files which need to be cached. To add or remove the file types from the list of file types to be cached, for the path attribute, modify the regular expressions to include or remove the appropriate file extension. Size of the cache can also be specified. The default is set to 10 GB under the “maxSize” attribute.

Additionally, if the product is SharePoint Server 2010, we can enable “SharePoint Server Publishing Infrastructure” at the site collection level where we need to use Object caching. Once the Publishing feature is enabled on the site, we can then enable Object caching by navigating to site settings -> Site Collection Object Cache.

Advantages of BLOB Cache

  • Disk based caching is extremely fast. Decrease in response time.
  • Eliminates the need for round trips between database and SharePoint servers for every request.
  • Security trimmed caching.
  • Can specify which files to be cached and can also restrict the types of files which need not be cached.
  • Setting BLOB cache for one web application does not affect performance of other web applications which do not have BLOB
  • cache configured.
  • The files are cached on the server only if it is requested for the first time on that WFE. Thus, only the required files are cached and each WFE maintains its local copy of cache.
  • Each server uses less CPU time and energy to serve the same page after the initial rendering.

Disadvantage of BLOB Cache

  • The site’s performance is temporarily affected while the files to be cached are first written on the disk.
  • BLOB caching can only be configured at web application level. There is one BLOB cache per web application. Hence, if there are two different site collections – one of which contains static (needs BLOB caching) and other dynamic (does not need BLOB caching), then we need to separate the two site collections and store them in two different web application.
  • In some scenarios where the files are large in size and number, BLOB caching may require lot of hard disk space and hence may need additional hard ware to accommodate the files. We need to use a hard drive which has sufficient space and which will be used by few processes as possible to avoid conflicts during cache retrieval.
  • As each WFE maintains it own copy of cache, the information (about which files need to be cached) is not synchronized. Thus, if WFE1 has “file1.jpg” cached but if WFE2 gets the request for that same file, WFE2 will make a round trip to SQL to fetch the file for the first time. It is not aware that the file is cached on WFE1.
  • Also, as the data is not synchronized, there are chances that each server can have different copies of the file and upon request the end user might see two different files.
  • In case few of the files are corrupted, we may need to reset the entire index file on WFE server and rebuild the cache.
  • BLOB caching works only for items stored in document libraries on SharePoint site.
  • BLOB caching cannot be used with Web Applications that use Web Gardening.

Performance:

Let us test the performance with and without blob cache. The performance of the page also depends on the amount of media and content (that is cached on the server) present on the page. If the content cached is more, then the performance improvement can be seen very easily. If there are lesser image or media files, then the performance improvement might go unnoticed.

e.g. Following are the page load time for a test page on SharePoint site. The page contains a image file – “SharePointDeveloperToolbar.jpg”. The following data considers the time taken for the file to load before and after the blob cache settings.

Page load time with blob cache

SharePoint BLOB Cache (Disk Based Caching) fundamentals

Approximately 0.015 seconds for that single image file.

Page load time without blob cache

SharePoint BLOB Cache (Disk Based Caching) fundamentals2

Approximately 0.031 seconds for the same image file.

The above is only for one single image file on the page. If we consider all the media elements on the page, then the difference can be seen easily.