Guides
How to use ccache in GitHub Actions
C and C++ builds recompile everything on every run.
5 min read
C and C++ builds recompile everything on every run.
Why it happens
ccache's store is not persisted, so it cannot short-circuit identical compilations.
How to fix it
- Cache ~/.ccache keyed on the compiler version and source hash
- Set CMAKE_C_COMPILER_LAUNCHER and CMAKE_CXX_COMPILER_LAUNCHER to ccache
- Print ccache -s at the end of the job so hit rate is visible
- Set max_size high enough — the default is often too small for CI
Your next build could be twice as fast, at half the price
Start free. Migrating away is the same one line, and we publish that diff too.
Related
How to make CI caches actually persistCaches are configured but hit rate is low.How to work around the 10 GB cache limitYour caches exceed 10 GB per repository and start silently evicting.How to share a build cache across repositoriesEach repository maintains its own cache for the same shared dependencies.How to share a Docker cache between jobsEach matrix leg rebuilds the same layers.