1.What is Blob Cache?
Disk-based Caching for Binary Large ObjectsA BLOB cache is a disk-based cache that stores binary large objects (BLOBs) such as frequently used image, audio, and video files, and other files that are used to display web pages. Each front-end web server maintains its own BLOB cache. When you enable a BLOB cache, you specify the file types to include in the cache and also the location of the BLOB cache. The first time that a BLOB file is requested, the file is copied from the database to the BLOB cache on the front-end web server. Future requests to the front-end web server for that same file are then served from the file that is stored in the BLOB cache, instead of being served from the database. This reduces the network traffic and the load on the database server.
2.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.Note : Please edit Web.config file with utmost care, as it may currupt your whole Farm, its recommended to edit this in presence of a skilled SharePoint Developer
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.
3. Flushing the Disk-based Cache:
We can flush the current site collection object cache. To do this, browse to the following location on the web site,Site collection administration -> site collection object cache -> disk based cache reset.
If we have multiple WFEs in the farm, each WFE will maintain its own copy of Disk-based Cache. SharePoint does not have a Web user interface (UI) to flush the disk-based cache on all the servers in a farm and neither is there an option to select a specific WFE.
When you flush the BLOB cache, you clear the contents of the BLOB cache for a web application. This is useful if the BLOB cache becomes out of sync with the content. For example, after you restore a content database, the BLOB cache will be out of sync with the content. To correct that situation, you must flush the BLOB cache
Caution : Flushing the BLOB cache for a web application affects all site collections in the web application.
Note : Considering SharePoint 2013, We cannot use the user interface to flush the BLOB cache Instead, you use Windows PowerShell and the SharePoint object model to complete this task.
To flush the BLOB cache
1) Verify that you have the following memberships:-
securityadmin fixed server role on the SQL Server instance.
-
db_owner fixed database role on all databases that are to be updated.
-
Administrators group on the server on which you are running Windows PowerShell cmdlets.
-
You must read about_Execution_Policies.
-
Add memberships that are required beyond the minimums above.
Note: If you do not have permissions, contact your Setup administrator or SQL Server administrator to request permissions. For additional information about Windows PowerShell permissions, see Permissions and Add-SPShellAdmin.
2) Copy the following code and paste it into a text editor, such as Notepad.
$webApp = Get-SPWebApplication "<WebApplicationURL>"
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp)
Write-Host "Flushed the BLOB cache for:" $webApp
3) Replace <WebApplicationURL> with the URL of the web application whose BLOB cache you want to clear
4) Save the file, and name it FlushBLOBCache.ps1.
Note: You can use a different file name, but you must save the file as an ANSI-encoded text file that has the file name extension .ps1.
5) On the Start menu, click All Programs.
6) Click Microsoft SharePoint 2013 Products.
7) Click SharePoint 2013 Management Shell.
8) Change to the directory where you saved the file.
9) At the Windows PowerShell command prompt, type the following command.
./FlushBLOBCache.ps1
4.The option provided in the Administration page for flushing the cache is only to the flush the cache on the web front end to which you are currently browsing.
if you would like to flush the complete binary large object (BLOB) caches associated with a specific Web Application on different Web front-end computers in a farm, then you can use the STSADM command to do so.
STSADM -o setproperty -propertyname blobcacheflushcount -propertyvalue 11 -url http://mywebapp:port
5.Internals of the blob cache functionality within SharePoint:
After enabling blob cache in web.config, do an IISRESET and browse to the /settings.aspx first, instead of home page (Collaboration portal site).When we browse to the settings.aspx, it will create the following files change.bin, dump.bin and flushcount.bin (all the files will be 1KB in size).
Browse to the home page now, it will create a folder PUBLISHINGIMAGES, all the images rendered from the database will be stored here and the above bin files will also get updated (we can see the difference in file size).
Every time when a new image file is rendered from the database, the image folder gets a copy of the image. The bin files (index) will get updated with an additional entry for the new file.
Every request from client will check the index file first. It will only check the cache index and not the image folder directly for the image. If the index file does not have an entry for the image, then the request is served from the database. During this time, a copy of the image will be stored in the images folder and the index file also gets updated, so that the next request will not go to the database.
6.What happens I manually delete just the image file in the cache folder or the image file in the cache folder gets corrupted?
We will not see the image on the client page; we get a broken image ‘X’.7.How are these cache files stored?
Filename.extension.cache is the file naming format.8.What can I do if the cached file gets corrupted?
Recommendation: We can reset the 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 get rebuilt.Workaround: If you do not want to reset the complete index. Find out the missing image and copy just that file to the cache folder, name it as “filename.extension.cache”
Refresh the page now; it should pick up the image.
9.How is the Index file maintained?
Every time when the web.config initializes, the index file is loaded from the blobcache folder to memory. All new entries will keep getting updated in index file when in memory.IISRESET /stop will flush the updated index file from memory to disc within the 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.
10.Can an Index file get corrupt?
Index file corruption is possible only when IIS crash or the index file is overwritten with wrong information. When IIS tries to load the index file from blobcache to memory and identifies that it is a 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.11.In a farm environment, is there any way of having all the WFEs' blob caches synchronized among each other?
No, this cannot be done because SharePoint maintains the index and the cache files individually on each server.12.In a single WFE environment using web gardening, how does blob caching function? Is there any sync that happens among the working processes?
Web gardening is not supported.13.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.
What are the limitations of SharePoint and blob caching 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.
Reference from: Technet & MSDN Blogs
No comments:
Post a Comment