다음을 통해 공유


SharePoint 2010: Configure and Flush Blob Cache

Enable BLOB Cache using PowerShell?

Web.config file changes can be made with "SPWebConfigModification" class. Let's 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 list of all file extensions that will be cached. File types are separated by the 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 a 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 the 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". The same method applies for additional parameters such as: Location, MaxSize, max-age, etc.

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

Sometimes, you may notice your changes don’t appear on the site. All you have to do is: flush the cache! Here is the PowerShell script 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

See Also