ccache -M: Cap the Cache Size
ccache -M sets the maximum size of the cache; ccache evicts the least recently used entries to stay under it.
A CI cache that grows unbounded eventually blows your cache storage quota or slows save/restore. Setting max_size keeps it bounded while retaining the hottest objects.
What it does
ccache -M sets the cache size ceiling (suffixes K, M, G, T). When the cache exceeds the limit, ccache evicts least-recently-used entries. The value is stored in the cache config, so it persists; CCACHE_MAXSIZE sets it per invocation via the environment.
Common usage
ccache -M 5G # cap at 5 GiB
ccache -M 500M # cap at 500 MiB
export CCACHE_MAXSIZE=2G # set via environment
ccache --max-files 0 # no file-count limit (size only)Options
| Flag / Setting | What it does |
|---|---|
| -M <size> | Set max cache size (e.g. 5G, 500M) |
| CCACHE_MAXSIZE | Environment form of max_size |
| --max-files <N> | Limit the number of cached files (0 = unlimited) |
| -M 0 | No size limit (unbounded, not for CI) |
| -p | Print the current configuration including limits |
In CI
Size the cache to a bit more than one clean build of the project so most objects survive between runs, but small enough to fit your CI cache quota and restore quickly. Set it once via CCACHE_MAXSIZE in the environment so it applies regardless of which step runs first. Pair with reading ccache -s to confirm eviction is not throwing away useful entries.
Common errors in CI
"Failed to parse max size" means a malformed value (use 5G, not 5GB or 5 G). A cache that never hits after restore despite a sane limit is usually a hashing issue, not a size issue. If the cache keeps filling and evicting within a single build, the limit is too small for the project; raise it.