Skip to content

ccache and sccache fill up to their limit and stay there. Here is how to set the limit

Compiler caches keep up to 5 or 10 GB by default. How to see what yours holds, lower the limit, or clear it when you finish a C, C++ or Rust project.

4 min read

Compiler caches save build time by remembering previous compilations. They are designed to fill up to a maximum and then recycle space. The defaults are generous: ccache keeps up to 5 GB and sccache up to 10 GB, which is a lot on a small Mac.

ccache -s 2>/dev/null
du -sh ~/Library/Caches/ccache 2>/dev/null

sccache --show-stats 2>/dev/null
du -sh ~/Library/Caches/Mozilla.sccache 2>/dev/null

Lower the limit

ccache -M 2G

# sccache reads an environment variable, add it to ~/.zshrc
export SCCACHE_CACHE_SIZE="3G"

Clear it

ccache -C
# sccache: stop the server, then remove its folder
sccache --stop-server
rm -rf ~/Library/Caches/Mozilla.sccache

The next build is slower while the cache refills. That is the whole trade-off.

Other compiled-language caches: Rust and Cargo, Bazel.

Common questions

Where is the ccache folder on a Mac?

Usually ~/Library/Caches/ccache. ccache -s shows the location and size.

How do I limit ccache size?

Run ccache -M with a size, for example ccache -M 2G.

Is it safe to clear ccache or sccache?

Yes. They only store compiler output. The next build is slower while it refills.

Read next