BlobCache - MOSS

What is BlobCache?

Disk-based Caching for Binary Large Objects

Disk-based caching controls caching for binary large objects (BLOBs) such as image, sound, and video files, as well as code fragments. Disk-based caching is extremely fast and eliminates the need for database round trips. BLOBs are retrieved from the database once and stored on the Web client. Further requests are served from the cache and trimmed based on security.

Enabling and Modifying Disk-based Caching for SharePoint sites.

Disk-based caching is disabled by default. To enable and customize the disk-based cache, you must modify the following statement in the web.config file for the SharePoint Web application.

By default, it looks like this:
<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="false" />

In order to improve the performance of your site, the BlobCache should be enabled.
<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" enabled="true" />

Example:

<BlobCache location="C:\blobCache" path="\.(gif|jpg|png|css|js)$" maxSize="10" max-age="86400" enabled="false"/>

In the preceding example:

• location is the directory where the cached files will be stored
• path specifies in the form of a regular expression which files are cached based on the file extension
• maxSize is the maximum allowable size of the disk-based cache in gigabytes
• max-age specifies the maximum amount of time in seconds that the client browser caches BLOBs downloaded to the client computer. If the downloaded items have not expired since the last download, the same items are not re-requested when the page is requested. The max-age attribute is set by default to 86400 seconds (that is, 24 hours), but it can be set to a time period of 0 or greater.
• enabled is a Boolean that disables or enables the cache.

Flushing the Disk-based Cache:

We can flush current site collection object cache.
Site collection administration -> site collection object cache -> disk based cache reset.

If we have multiple WFE in a farm, each WFE will maintain its own copy of Disk-based Cache. MOSS does not have a Web user interface (UI) to flush Disk-based Cache on all the servers in a farm and there is no option to select specific WFE.

When we use web user interface to flush, reset will happen at the WFE server where the current IE session established. Eg:: Configure DNS round robin for a URL, open IE(1) and browse the site, it establish connection with WFE1. Open another IE(2) and browse the site, it establish connection with WFE2. When you do flush thru IE(1), WFE1 disk-based cache will get reset, do the same thru IE(2), WFE2 cache will get reset.

We have to use STSADM command to flush all binary large object (BLOB) caches associated with a specific Web Application on different Web front-end computers in a farm

STSADM -o setproperty -propertyname blobcacheflushcount -propertyvalue 11 -url https://mywebapp:port

How BOLBCACHE works:

After enabled blobcache in web.config, do IISRESET and browse /settings.aspx first, instead of home page (Collaboration portal site).

If we browse the settings.aspx, it creates Change.bin, dump.bin and flushcount.bin (all the files will be in 1KB size)

Browse the home page now, it will create a folder PUBLISHINGIMAGES folder, all the images rendered from database will be stored here and the above bin files also will get updated (we can see the difference in file size)

Every time when a new image file rendered from database, the image folder gets a copy of the image. The bin files (index) will get updated with additional entry.

Every request from client will check the index file first; if the required image is not there in index, the request will go to database to get page content and image. It will not check the image folder whether the image is there or not. If the index file says there is no such image then the request goes to database, after the image rendered the image folder and index file get updated, so that next request will not go to database.

What happens, if the image is not there in cache folder or image file is corrupted?

We will not get the image; we get ‘X’ in place of image.

What you mean by image file not there?

Filename.jpg.cache file is missing.

What you mean by image corrupted?

When you try to open the image file using image viewer (use IE), it will show ‘X’, because it is not a image file format (we get the same ’X’ in SharePoint page as well)

Solution: We have to reset index file. Site settings -> Site collection object cache -> Check the box for “Force this server to reset its disk based cache”. It will completely delete all the images and reset the bin files back to 1KB, so that next request will go to database and the complete index will be getting rebuilt.

Workaround: If you do not want to reset the complete index. Find out the missing image and copy to the image folder, name it as “filename.JPG.cache”
Refresh the page now; it should pick up the image.

Index file update:

Everytime when web.config initialize the index file loaded from blobcache folder to memory, all new entries will keep getting updated in index file where in memory.
IISRESET /stop will dump the updated index file from memory to blobcache folder.
IISRESET /start will load the index file from blobcache folder to memory.
As long as the application pool is alive the index file will be getting updated in memory itself.

Index file corruption:

Index file corruption is possible only when IISAdmin crashed or the index file overwritten with wrong information. When IIS try to load index file from blobcache to memory and identifies that, it is corrupted file (not a valid file), it will get completely rebuilt (flush) as fresh file (1KB), all the old entries and images will be lost.

Q & A:

1. In a farm environment, is there any way of having all the WFEs' blob caches synchronized among each other?
No, it cannot be synchronized. When a new file is added, SharePoint loads in memory the list of “cached” files in order to avoid checking the file system every time.

2. In a single WFE environment using web gardening, how does blob caching function? Is there any sync that happens among the working processes?
BLOB cache doesn’t support web gardening. The reason for that is because thre is different processes to access the same blobcache (there’s one blobcache per IIS web Site). As result, the second web process is not able to access the BlobCache. When a recycle occurs and the original W3WP process dies gracefully the lock released and the new W3WP process is then able to access BlobCache.

3. What would be the best way of using blob cache in a farm environment (best practices)?
If the requirement is to “centralize” static cached files, then 3rd party content distribution network (CDN) solutions like Akamai need to be used.

4. What limitations does SharePoint have to deal with blob cache in a farm environment?
a. Blob caching does not work with Web Gardening.
b. Blob caching does not synchronize data across WFEs – so we might be seeing different versions of the files for a short duration across different WFE servers.