Ccache

= Description =

is a compiler cache. helps to avoid repeated recompilation for the same C and C++ files by fetching result from the 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

= Basic setup (portage integration) =

To get running you need a few steps:
 * Install the package via usual means:
 * Create cache directory:
 * Set initial config:
 * Enable support in :

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

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

= General notes =

works by prepending to  variable:

triggers the same behaviour in.

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

Useful variables and commands
Some variables:
 * Variable points to cache root directory.
 * Variable 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.

= Gentoo specifics/gotchas =

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