Learn more about SQL Server tools

mssqltips logo
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 

Enable the SharePoint Blob Cache For Performance Gains


By:   |   Read Comments   |   Related Tips: > Sharepoint

Attend this free live MSSQLTips webcast

Tips and Tricks to Growing Your SQL Server Estate from SMB to Enterprise Scale
Thursday, June 28, 2018 - click here to learn more


Problem

SharePoint 2007 and 2010 allows users to store media files such as pictures and videos and display them on a SharePoint page. These media files and other page artifacts (like css and javascript) can be very slow to load. This is because each time the files are accessed they are pulled from the SharePoint Content Database by default. For external facing sites in particular, images and javascript can consume most of the load time for a page.

Solution

Let's see how we can use a feature called the BLOB Cache to speed up loading of media and other files.

BLOB caching, or disk-based caching, is an out of the box (OOTB) caching mechanism that is built into the MOSS 2007 and SharePoint Server 2010 platforms. It is commonly used to speed-up access to large and relatively static resources that are stored in content databases, such as images, videos, javascript files, and more. Performance improvements are gained by storing these assets on web servers once they’ve been requested by a client. This allows SharePoint to serve subsequent requests for such assets directly from web servers instead of round-tripping to the content database each time a request for such an asset is received. For most SharePoint sites, this type of caching can significantly lighten the load on your SQL Servers and back-end network.

BLOB Caching is controlled through the web.config file for each of the IIS web sites that is associated with a Web application, and it is not enabled by default. Enabling BLOB caching is as simple as setting the enabled attribute to true in the < BlobCache/> web.config element as shown below.

< BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|png|css|js|avi|wmv)$" 
	maxSize="10" max-age="43200" enabled="true" /> 
Web.Config Snippet

Remember to reset IIS after any changes to a web.config by typing IISRESET /noforce in a command prompt window.

The "maxSize" attribute is the size in gigabytes. So any files over 10GB in our example won't be cached. You can specify any file types you want to be cached in the "path" attribute, just add a pipe symbol and add the file extension. Finally, take note of the "location" attribute. If this folder doesn't exist, it will be created. You can see this in the Event Viewer.

cache folder

Resources that are served from a web servers BLOB cache when the max-age attribute is used are only re-requested after the max-age interval has elapsed or the browser’s local cache has been cleared. In our example above, our "max-age" is set to 43200 seconds. This is equivalent to 12 hours. Change this value based on your environments needs.

If the cache needs to be flushed before the expiration is reached, you can reset the object cache. In SharePoint 2007, a Site Collection Administrator can perform a reset. To do so, go to Site Collection Administration, Site Collection Object Cache, and check Disk Based Cache Reset.

site collection object cache

If your SharePoint 2007 farm consists of more than one web front-end, you may not see the objects flushed. This is because the request is only sent to the web server that is currently in use by the logged-in user. However, you can easily overcome this by using STSADM. The following command will reset the BLOB Cache on all web servers in the SharePoint 2007 farm:

STSADM -o setproperty -propertyname blobcacheflushcount -propertyvalue 
11 -url https://url-of-web-application 

In SharePoint 2010, you'll use the following PowerShell commands to flush the BLOB Cache:

$webApp = Get-SPWebApplication "<WebApplicationURL>"
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp)
Next Steps


Last Update:


next webcast button


next tip button



About the author
MSSQLTips author Wahid Saleemi Wahid Saleemi

View all my tips





Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Email me updates 


Signup for our newsletter
 I agree by submitting my data to receive communications, account updates and/or special offers about SQL Server from MSSQLTips and/or its Sponsors. I have read the privacy statement and understand I may unsubscribe at any time.



    



Learn more about SQL Server tools