osx - How to clear browser disk and memory caches from the Terminal in Mac OS X

24
2013-08
  • Michael Prescott

    I'm debugging an Adobe Flash application my team and I have developed. Each time we update the application SWF files, we need to clear the browser caches. We also need to delete AssetCaches and setup a few other things.

    So, I have a simple Bash script that deletes Firefox's file cache, Flash's shared objects, Flex's AssetCache, and Safari's Cache.db file. This is all fine, except not thorough. Safari still retains the previously loaded SWF files in memory cache. I believe Firefox is doing this also, but intermittently. This makes debugging a bit of a headache to say the least.

    The work-around is to use each browser's GUI to clear their disc and memory caches. Just a bad work-flow all around. It would be awesome if I could add another line or two to my Bash script and wipe the memory cache along with the other tasks. How do I do this?

  • Answers
  • Daniel Beck

    You just need to tell your browser that you cleared the cache. Either by restarting:

    killall Safari
    open -a Safari
    

    Or by clearing the cache using GUI scripting, e.g. the following AppleScript:

    tell application "Safari" to activate
    tell application "System Events"
        tell application process "Safari"
            click (first menu item whose name is "Empty Cache…") of first menu of (first menu bar item whose name is "Safari") of first menu bar
        end tell
        keystroke return
    end tell
    

    You should be able to call it from your shell script using osascript name.scpt, or save as Application and open it.


  • Related Question

    Which is better? High cache memory or low cache?
  • soul

    Which is better? High cache memory or low cache? And what exactly is their difference.


  • Related Answers
  • William Hilsum

    Always - More the better.

    If you are talking about the CPU cache, Wikipedia says it best -

    A CPU cache is a cache used by the central processing unit of a computer to reduce the average time to access memory. The cache is a smaller, faster memory which stores copies of the data from the most frequently used main memory locations. As long as most memory accesses are cached memory locations, the average latency of memory accesses will be closer to the cache latency than to the latency of main memory.