LinuxCommandLibrary

ccache

TLDR

Show cache statistics

$ ccache -s
copy
Clear the cache
$ ccache -C
copy
Set maximum cache size
$ ccache -M [5G]
copy
Show configuration
$ ccache -p
copy
Zero statistics
$ ccache -z
copy
Run compiler through ccache
$ ccache [gcc] -c [file.c]
copy
Show cache directory
$ ccache -k cache_dir
copy

SYNOPSIS

ccache [options]
ccache compiler [compileroptions_]

DESCRIPTION

ccache is a compiler cache that speeds up recompilation by caching previous compilations. When the same compilation is detected, it returns the cached result instead of recompiling.
Supports GCC, Clang, MSVC and similar compilers for C, C++, Objective-C, CUDA, and assembler.

PARAMETERS

-s, --show-stats

Show cache statistics
-z, --zero-stats
Zero statistics counters
-C, --clear
Clear entire cache
-M, --max-size size
Set maximum cache size (e.g., 5G, 500M)
-p, --show-config
Show current configuration
-k, --get-config key
Get configuration value
-o, --set-config key=value
Set configuration value
--cleanup
Clean up cache to stay within size limit
-V, --version
Show version

SETUP

Symlink method:

$ ln -s /usr/bin/ccache /usr/local/bin/gcc
ln -s /usr/bin/ccache /usr/local/bin/g++
copy
Environment variable:
$ export CC="ccache gcc"
export CXX="ccache g++"
copy

REMOTE CACHING

Supports remote caching via HTTP, Redis, or NFS for sharing across build machines.

CAVEATS

Only caches single-file compilations. Multi-file compilation and linking fall back to real compiler. Produces identical output to direct compilation.

SEE ALSO

gcc(1), clang(1), make(1), distcc(1)

Copied to clipboard