locked
Clearing CCM Cache RRS feed

  • Question

  • We are successfully deploying many applications via SCCM 2007.  The problem we are running into now is getting the CCM Cache folder to clear out.  Is there any way to clear the cache folder automatically on a schedule or if a program needs to be downaloaded and there is not enough space in the cache?
    Tuesday, May 20, 2008 7:11 PM

Answers

  • We do remove content from the cache automatically if space is needed, and there is content that is no longer required. You should not have to clean it out manually.

     

    Other than that, check the SDK. There's nothing built into the product to do this on a schedule, as it is managed automatically.

    Wednesday, May 21, 2008 4:35 AM

All replies

  • I have had limited success with this script when run from the DP. 

    -----clearcache.vbs-----------

    on error resume next
    dim oUIResManager
    dim oCache
    dim oCacheElement
    dim oCacheElements

    set oUIResManager = createobject("UIResource.UIResourceMgr")

    if oUIResManager is nothing then
    wscript.quit
    end if

    set oCache=oUIResManager.GetCacheInfo()

    if oCache is nothing then
      set oUIResManager=nothing
      wscript.quit
    end if

    set oCacheElements=oCache.GetCacheElements

    for each oCacheElement in oCacheElements
      oCache.DeleteCacheElement(oCacheElement.CacheElementID)
    next

    set oCacheElements=nothing
    set oUIResManager=nothing
    set oCache=nothing
    wscript.quit
    -----------------------

     

    I haven't tested it with SCCM but I would assume that it should work. 

     

    I will say that as a login script or run outside of a SMS/SCCM package it has never failed.  Running it as a package sometimes will.  Basically because you can't clean this file since it is in use Smile

    • Proposed as answer by Sergey Dorofeev Wednesday, November 6, 2013 2:33 PM
    Tuesday, May 20, 2008 7:33 PM
  • We do remove content from the cache automatically if space is needed, and there is content that is no longer required. You should not have to clean it out manually.

     

    Other than that, check the SDK. There's nothing built into the product to do this on a schedule, as it is managed automatically.

    Wednesday, May 21, 2008 4:35 AM
  • We use this script mainly because we sometimes have packages that just don't remove from the cache.  We have on a number of occasions observed 4 or 5 versions of the same package still sitting in the cache.  This code is taken from the SDK for client actions.

     

    Wednesday, May 21, 2008 1:14 PM
  • How does it determine if the program is no longer required to stay in cache?  If we advertise multiple applications to the same  computer then how does it know what cached programs to get rid of?  We have several programs that have fairly large install bases.  i.e. Adobe Creative suite is about 2 GB of installs.  If this and a few more applications are assigned, then the cache can fill up quick.
    Wednesday, May 21, 2008 3:16 PM
  • If I remember correctly, we wait until the program has successfully run. We then mark the content as tombstoned, which means it can be deleted if the space is required.

     

    Thursday, May 22, 2008 4:13 AM
  • Hi I've added some more logic around the code above.

    This code will now check if the cached folder is still referenced by any sms installation and when it was last referenced, it will then only remove cached folder that are nolonger reference and were last user more than 30 days ago.

    I've also added some logging which you may find useful.

     

    'Const declaration
    Const ForAppending = 8
    Const ForReading = 1

    '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    'Variable declaration
    on error resume next
    dim oUIResManager
    dim oCache
    dim oCacheElement
    dim oCacheElements
    dim objToday  'Todays date
    dim objfso    'File System Object

    'Set File System Object
    '------------------------------------------------------------------------------------------------------------------------------------
    Set objfso = CreateObject("Scripting.FileSystemObject")

    'Set log file strPath
    '------------------------------------------------------------------------------------------------------------------------------------
    strLogPath = "c:\logs\CCMCache.log"

    'Create or open log file
    '------------------------------------------------------------------------------------------------------------------------------------
    If objfso.FileExists(strLogPath) Then
     if objfso.getfile(strLogPath).size >1024000 then
      If objfso.FileExists(strLogPath & ".old") then
       objfso.DeleteFile(strLogPath & ".old")
       objfso.MoveFile  strLogPath,strLogPath & ".old"
      else
      objfso.MoveFile strLogPath,strLogPath & ".old"
      end if
     end if
     Set objLogFile = objfso.OpenTextFile(strLogPath, ForAppending, True)
    else
     Set objLogFile = objfso.CreateTextFile(strLogPath)
    end if
    objLogFile.WriteLine("******************************************************************************")
    objLogFile.WriteLine("Scritp starting at " & now)


    set oUIResManager = createobject("UIResource.UIResourceMgr")

    if oUIResManager is nothing then
       objLogFile.WriteLine("UIResManager is set to nothing")
     wscript.quit
    end if

    set oCache=oUIResManager.GetCacheInfo()

    if oCache is nothing then
       set oUIResManager=nothing
     objLogFile.WriteLine("oCache is set to nothing")
     wscript.quit
    end if

    lngFreeSpace = oCache.FreeSize
    lngTotalSpace = oCache.TotalSize
    lngStartUsedSpace = lngTotalSpace - lngFreeSpace
    objLogFile.WriteLine("Total cache size is " & lngTotalSpace & "MB")
    objLogFile.WriteLine("Amount of space used is " & lngStartUsedSpace & "MB")


    set oCacheElements=oCache.GetCacheElements
    objToday =  cdate(date)
    objLogFile.WriteLine(vbtab & "ContentID" & vbtab & "ContentSize" & vbtab & "ContentVersion" & vbtab &  "LastReferenceTime" & vbtab & "ReferenceCount"& vbtab & "Location" )
    for each oCacheElement in oCacheElements
       objLogFile.WriteLine(oCacheElement.CacheElementID)
       objLogFile.WriteLine(vbtab & oCacheElement.ContentID & vbtab & oCacheElement.ContentSize & vbtab & vbtab & vbtab & oCacheElement.ContentVersion & vbtab &  oCacheElement.LastReferenceTime & vbtab & oCacheElement.ReferenceCount & vbtab & oCacheElement.Location )
       iRefCount=(oCacheElement.ReferenceCount)
       iDateDiff=datediff ("d",oCacheElement.LastReferenceTime,objToday)
       objLogFile.WriteLine(vbtab & "ReferenceCount is " & iRefCount &"-"&  iDateDiff)
     objLogFile.WriteLine(vbtab & "Number of day since this cached folder was used " &  iDateDiff)
       if iRefCount = 0 and iDateDiff > 30 then
          objLogFile.WriteLine(vbtab & "Mark for delete")
          oCache.DeleteCacheElement(oCacheElement.CacheElementID)
       end if
    next

    lngFreeSpace = oCache.FreeSize

    objLogFile.WriteLine("Currently in Cache size is " & lngTotalSpace - lngFreeSpace & "MB")

    lngEndUsedSpace = lngTotalSpace - lngFreeSpace
    objLogFile.WriteLine("Total amount of space freed up was " & lngStartUsedSpace - lngEndUsedSpace & "MB")

    set oCacheElements=nothing
    set oUIResManager=nothing
    set oCache=nothing

    'Closing log file
    objLogFile.WriteLine("Script finnished at " & now)
    objLogFile.Close()

    Friday, August 1, 2008 1:51 PM
  • Hello Wally,

    We are working for the first time with SCCM and I have exactly the same problem. What I would like to know it how often the cache is empty automatically by the client. We need to deploy like 8GB to 10GB of soft (most are Adobe products, and they are very huge). Do you have any other suggestions?

    Alain K.

    Wednesday, March 30, 2011 8:13 AM
  • See http://support.microsoft.com/kb/839513. It states SMS, but it's also valid for ConfigMgr.
    Torsten Meringer | http://www.mssccmfaq.de
    • Proposed as answer by Richard Archer Friday, December 13, 2013 10:36 AM
    Wednesday, March 30, 2011 9:25 AM
  • If you wish to remove persisted cache items too then change the line:

      oCache.DeleteCacheElement(oCacheElement.CacheElementID)

    to:

      oCache.DeleteCacheElementEx oCacheElement.CacheElementID, true

    The information about which can be found at: http://msdn.microsoft.com/en-us/library/cc144355.aspx

    Richard


    Thursday, May 12, 2011 11:46 AM
  • This works on both XP and 7 32 and 64 bit machines.

     

    Dim objFSO
    Dim objFolder
    Dim objSubFolder
    Dim winsh
    Dim winenv

     'deletes folders with a date modified of 120 day or older
    Const intDaysOld = 120
    set winsh = CreateObject("WScript.Shell")
    set winenv = winsh.Environment("Process")
    windir = winenv("WINDIR")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'looks for \system32\ccm\cache for 32bit
    if objFSO.FolderExists (windir & "\system32\ccm\cache") Then
    Set objFolder = objFSO.GetFolder(windir & "\system32\ccm\cache")
    For Each objSubFolder In objFolder.SubFolders
                    If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
               objSubFolder.Delete True
        End If
    Next
      Wscript.quit
    End if
    'looks for \sysWOW64\ccm\cache for 64bit
    if objFSO.FolderExists (windir & "\sysWOW64\ccm\cache") Then
    Set objFolder = objFSO.GetFolder(windir & "\sysWOW64\ccm\cache")
     For Each objSubFolder In objFolder.SubFolders
                    If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
               objSubFolder.Delete True
        End If
    Next
    End if

    Thursday, November 10, 2011 2:37 PM
  • I don't recommend using that script. It will delete files from the cache by using the FileSystemObject, which is a bad idea, because the ConfigMgr client is not aware of that changes then. Running a advertisement that was previously cached will fail then!
    You have to use the DeleteCacheElementEx method (http://msdn.microsoft.com/en-us/library/cc144355.aspx; as Richard already mentioned) if you want to delete items from the cache.


    Torsten Meringer | http://www.mssccmfaq.de
    Thursday, November 10, 2011 3:26 PM
  • Yes, but what are you basing your decision on when it comes to "...if space is needed,..." You are probably only basing it on if space is needed for more CCM cache, correct? I currently am running into a problem where I need more space. I just need to know if it will hurt anything systematically, if I delete this data. Im not worried about the need for the cache to complete installations.
    Monday, February 22, 2016 10:45 PM
  • Yes, but what are you basing your decision on when it comes to "...if space is needed,..." You are probably only basing it on if space is needed for more CCM cache, correct?
    Exactly! I'm having the problem where our lab computers ran out of space while CCM is happily keeping 40GB in its cache.
    Tuesday, March 29, 2016 2:33 PM
  • This code will now check if the cached folder is still referenced by any sms installation and when it was last referenced, it will then only remove cached folder that are no longer reference and were last user more than 30 days ago.

    What defines "no longer referenced"? I've got a package installed on a bunch of workstations which has 32GB of install files (and, due to that, we have the cache size set to 40GB). Once that package is installed, I don't want 32Gb of files hanging around in the cache.

    Tuesday, March 29, 2016 2:58 PM