Sunday 17 November 2013

Configure and Flush Blob Cache in SharePoint 2010

Enable BLOB Cache using PowerShell?



Why not! Web.config file changes can be made with "SPWebConfigModification" class. Lets utilize that to make a web.config change to enable BLOB cache:

BLOB Cache Configuration has the following Parameters: 

  • location - Is the file system folder where SharePoint server stores cached files.Make sure you select the BLOB cache location on a drive with sufficient disk space!
  • path - Is a lists all file extensions that will be cached. File types are separated by vertical pipe character.
  • maxSize - In GB, disk space that the BLOB cache will occupy. If BLOBs exceeds this limit, SharePoint will delete older items in the cache to make room for newer items.
  • max-Age - In seconds. It tells How long Browser can cache these files without making request to the server. Use it with value: 1814400 (Three Weeks), if you get: HTTP 304 error!
  • enabled - Sets BLOB Cache ON or OFF. Make it "false" to disable BLOB Cache.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web Application
$WebApp = Get-SPWebApplication "http://riponkundu.blogspot.in"

#Create a web.config modification
$WebconfigMod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$WebconfigMod.Path = "configuration/SharePoint/BlobCache"
$WebconfigMod.Name = "enabled"
$WebconfigMod.Sequence = 0
$WebconfigMod.Owner = "BlobCacheModification"
$WebconfigMod.Type = 1
$WebconfigMod.Value = "true"
    
#Apply the web.config change
$WebApp.WebConfigModifications.Add($WebconfigMod)
$WebApp.Update()
$WebApp.Parent.ApplyWebConfigModifications()


This will enable BLOB Cache. If you want to disable BLOB cache, just change the Parameter "enabled" to "false". Same method applies for additional parameters such as: Location, MaxSize, max-age etc.




How to Flush(Reset/Clear) BLOB cache in SharePoint 2010



Some times, You may notice your changes don’t appear in the site. All you have to do is: Flush the Cache! Here is the PowerShell to flush the BLOB cache (No GUI to do this!).


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$webApp = Get-SPWebApplication "http://riponkundu.blogspot.in"
[Microsoft.SharePoint.Publishing.PublishingCache]::FlushBlobCache($webApp)
Write-Host "BLOB Cache Flushed for:" $webApp



No comments:

Post a Comment