ccache (or “Ccache”) is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.
- 2019-10-22: Version 3.7.5 has been released
- 2019-09-12: Version 3.7.4 has been released
- 2019-08-17: Version 3.7.3 has been released
- 2019-07-19: Version 3.7.2 has been released
- 2019-05-01: Version 3.7.1 has been released
- 2019-04-23: Version 3.7 has been released
- 2019-04-03: Web site moved from ccache.samba.org to ccache.dev
- 2019-01-14: Version 3.6 has been released
- 2019-01-02: Version 3.5.1 has been released
- 2018-10-15: Version 3.5 has been released
- Keeps statistics on hits/misses.
- Automatic cache size management.
- Can cache compilations that generate warnings.
- Easy installation.
- Low overhead.
- Optionally uses hard links where possible to avoid copies.
- Only knows how to cache the compilation of a single C/C++/Objective-C/Objective-C++ file. Other types of compilations (multi-file compilation, linking, etc) will silently fall back to running the real compiler.
- Only works with GCC and compilers that behave similar enough.
- Some compiler flags are not supported. If such a flag is detected, ccache will silently fall back to running the real compiler.
If you ever run
make clean; make, you can probably benefit from
ccache. It is common for developers to do a clean build of a project for a
whole host of reasons, and this throws away all the information from your
previous compilations. By using ccache, recompilation goes much faster.
Another reason to use ccache is that the same cache is used for builds in different directories. If you have several versions or branches of a software stored in different directories, many of the object files in a build directory can probably be taken from the cache even if they were compiled for another version or branch.
A third scenario is using ccache to speed up clean builds performed by servers or build farms that regularly check that the code is buildable.
You can also share the cache between users, which can be very useful on shared compilation servers.
Is it safe?
The most important aspect of a compiler cache is to always produce exactly the same output that the real compiler would produce. This includes providing exactly the same object files and exactly the same compiler warnings that would be produced if you use the real compiler. The only way you should be able to tell that you are using ccache is the speed.
ccache of course tries to provide these guarantees. However:
- Compilers are moving targets. Newer compiler versions may, and often do, introduce features that ccache can't foresee. In some cases it's also very hard for ccache to handle the compiler behaviors in a good way, especially in a way that is backward compatible with legacy compilers.
- There are some known corner cases where ccache can fail to detect that source code files have changed since a previous compilation. These limitations are listed under caveats in the manual.
If you experience any bugs or undocumented limitations, please report them.