Ccache

Article description::helps avoid repeated recompilation for the same C and C++ object files by fetching result from a cache directory.

Compiler cache is typically useful for:


 * Developers who rebuild the same/similar codebase multiple times and use to test patches.
 * Users who frequently play with USE-flag changes and end up rebuilding the same packages multiple times.
 * Users who use live ebuilds extensively.
 * Installing very big ebuilds, such as Chromium or LibreOffice, without fear of losing multiple hours of code compilation due to a failure.

Initial setup
Create the cache directory:

Set initial configuration file:

Enable support in :

Done! From now on all builds will try to reuse object files from cache.

Compression
ccache has the ability to perform compression on content, you can enable it in ccache.conf

Man page
Manual page for (see ) is a great source of various knobs to make caching more robust and aggressive.

General notes
works by prepending to PATH variable:

triggers the same behavior in.

You can also enable for your current user and reuse the same cache directory:

Useful variables and commands
Some variables:


 * Variable CCACHE_DIR points to cache root directory.
 * Variable CCACHE_RECACHE allows evicting old cache entries with new entries:

See for many more variables.

Some commands:


 * Command shows cache hit statistics:


 * Command drops all caches:

See for many more commands.

is a wrapper
For before   used to be a wrapper binary. This means by default ccache is not safe to use and leads to errors like. will fix it.

To pass through a binary I suggest using

in all your files. also has a nice side-effect of not invalidating your cache if compiler itself was rebuilt without version changes.

Caveats
Before using advanced options make sure you understand what is being used as a cache key by. By default these are:


 * Timestamp and size of a compiler binary (beware of shell and binary wrappers)
 * Compiler options used
 * Contents of a source file
 * Contents of all include files used for compilation