How to Clear the SCCM Cache (ccmcache) Safely
Clear the SCCM cache through the client, not through Explorer. Use the Delete Files button on the Cache tab of the Configuration Manager control panel, or the UIResource.UIResourceMgr COM object in PowerShell. Both remove the files and the client's record of them together.
What ccmcache holds
C:\Windows\ccmcache is the download folder of the SCCM client. The client puts content there before it runs an install.
- Application content, one folder per deployment type and content version.
- Package content for classic packages and programs.
- Software update files.
- Task sequence content that is downloaded before the task sequence starts.
Each item sits in a subfolder with a short name, such as 1, 2 or a. The names tell you nothing about what is inside. The client keeps the link between folder and content in WMI.
The default cache size is 5120 MB. Content stays in the cache after an install. The client reuses it for a repair or a reinstall, and for some uninstall commands.
The client already cleans up on its own
You do not need to clear the cache on a schedule. When a new download needs room, the client deletes old content by itself. It starts with the content that was used longest ago.
The client does not delete content that was used in the last 24 hours. It also does not delete content that is marked as persistent, or content that an install is using right now.
Clear the cache by hand only for a reason:
- The disk is almost full.
- A download fails because the cache has no room it can free.
- You suspect a damaged download and want the client to fetch a fresh copy.
Why you should not delete the folders in Explorer
The client tracks every cache item in WMI: the content ID, the folder and the size. If you delete a folder in Explorer, the files are gone but the record stays.
This causes two problems.
- The client still counts the deleted content as used space. The cache looks full when the folder is empty.
- The client can believe the content is still there. The next install then starts from an empty or missing folder and fails.
The methods below remove the files and the record together.
Clear the cache from the control panel
- Open Control Panel on the client.
- Open Configuration Manager.
- Select the Cache tab.
- Select Configure Settings. This needs administrator rights.
- Select Delete Files.
- Leave Delete persisted cache content clear, unless you want that content gone too.
- Select Yes to confirm.
Content that is in use stays. Run the action again after the running install ends.
Clear the cache with PowerShell
The client exposes its cache through the UIResource.UIResourceMgr COM object. Run these commands in an elevated PowerShell window on the client.
First, look at what is in the cache:
$mgr = New-Object -ComObject 'UIResource.UIResourceMgr'
$cache = $mgr.GetCacheInfo()
$cache.Location
$cache.TotalSize
$cache.FreeSize
$cache.GetCacheElements() |
Sort-Object LastReferenceTime |
Select-Object CacheElementID, ContentID, Location, ContentSize, LastReferenceTime
TotalSize and FreeSize are in MB. ContentSize is in KB. ContentID is the package ID or the content ID, so you can see which item is the large one.
Delete every item:
$mgr = New-Object -ComObject 'UIResource.UIResourceMgr'
$cache = $mgr.GetCacheInfo()
foreach ($item in $cache.GetCacheElements()) {
$cache.DeleteCacheElement($item.CacheElementID)
}
Delete only the items that were not used in the last 30 days:
$mgr = New-Object -ComObject 'UIResource.UIResourceMgr'
$cache = $mgr.GetCacheInfo()
$cutoff = (Get-Date).AddDays(-30)
$old = $cache.GetCacheElements() | Where-Object { $_.LastReferenceTime -lt $cutoff }
foreach ($item in $old) {
$cache.DeleteCacheElement($item.CacheElementID)
}
The second script is the safer one for many computers. It keeps content that a recent deployment may still need.
To run the script on many clients, add it under Software Library, Scripts in the console and run it on a collection. Test it on a few computers first. More examples are in the script library.
What happens after you clear the cache
- Installed applications stay installed. The cache holds only the install files.
- A required deployment that has not run yet downloads its content again.
- A repair or reinstall from Software Center downloads the content again.
- An uninstall command that needs the original files downloads the content first.
On a slow link, the new downloads cost time and bandwidth. Do not clear the cache on a whole branch office right before a large deployment.
Change the cache size
If large applications fail to download, the cache may be too small. Content that is larger than the whole cache can never download. CAS.log on the client shows this.
| Method | How |
|---|---|
| Client settings (best for many clients) | In the console, open Administration, Client Settings. In the Client Cache Settings group, set Configure client cache size to Yes. Then set the maximum size in MB or as a percentage of the disk. |
| Control panel (one client) | On the Cache tab, select Configure Settings and move the slider. |
| PowerShell (one client) | Set the TotalSize property of the cache object, in MB. |
| Client install | Use the SMSCACHESIZE property on the ccmsetup command line. |
$mgr = New-Object -ComObject 'UIResource.UIResourceMgr'
$cache = $mgr.GetCacheInfo()
$cache.TotalSize = 20480
Size the cache for your largest piece of content, plus room for the monthly updates. A cache that is larger than the free disk space does not help.
Persistent content
You can mark content so that the client never removes it on its own. For an application, open the deployment type and select the Content tab. Tick Persist content in the client cache.
Use this option rarely. Persistent content takes cache space for good. The space left for other downloads gets smaller, and large deployments start to fail for lack of room.
Good uses are small: a tool that a script runs again and again, or files that an uninstall needs later.
Check the result
- Open the Cache tab again, or read
FreeSizein PowerShell. The free space is now larger. - Open
CAS.loginC:\Windows\CCM\Logs. It records the deleted items. - Start the failed deployment again from Software Center.
If the install still fails after a clean download, the cache was not the cause. Follow the steps in how to troubleshoot a failed SCCM application deployment.
Comments