When there are substantial dependencies across an application, even the tiniest code change might result in lengthy recompilation times, which is a challenge when managing a vast code base. This article explains what a Ccache is. The following describes how does Ccache works, how to use it, and its features.
If only the compiler could access a history of builds that mapped hashed source files from earlier compiles that had already been pre-processed to the expected output object files. The compiler would therefore be able to skip the majority of the syntax and dependency analysis work that is often required and go straight to low-level optimization and object generation using those hashed files and the build map as input.
What is Ccache?
Ccache is a cache tool for compilers. By caching earlier compositions and identifying when the same compilation is being performed again, it expedites recompilation. A typical application is in CI/CD systems.
How does Ccache work

This is precisely how Ccache Works. In essence, it is a C and C++ compiler cache.
1. $ make clean; make
You are aware of the advantages if you have ever found yourself running multiple times in one day. By identifying whether the same compilation is being performed again and caching the results of prior compilations, it expedites recompilation.
Now included with the Intel oneAPI DPC++/C++ Compiler 2025.1 is Ccache support.
Because of its meticulous design, Ccache consistently generates the same compiler output as if it weren’t used. You should only be able to identify that you are utilising ccache by its speed. A source file’s text is scrambled after the C preprocessor is called during compilation. After this hash is used to query the cache, one of two outcomes may occur:
- A cache miss: The object file that is produced is saved in the cache after the C/C++ compiler is called. It want to avoid this situation as much as possible because the compiler is slower than reading a cache file.
- A hit to the cache: There is no need to launch a compiler because the pre-compiled object file is instantly accessible in the cache.
If your cache is big enough, you can clean your build directory and rebuild everything without using the compiler after creating a project from scratch for the first time.
Using Ccache with the Intel oneAPI DPC++/C++ Compiler its benefits are also available with SYCL code! |
Use Ccache
Ccache is compatible with Linux and Intel compilers. It can also be used with the Intel oneAPI DPC++/C++ Compiler C++ frontend driver icpx to compile SYCL programs.
Example
Use ccache to precede your compilation command for direct compilations:
1. ccache icx -c test.c
2. ccache icpx -fsycl -c sycl_test.cpp
When using CMake, set CMAKE_CXX_COMPILER_LAUNCHER to ccache:
cmake -DCMAKE_CXX_COMPILER=icpx -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..
The LLVM_CCACHE_MAXSIZE and LLVM_CCACHE_DIR options, which are provided to the CCACHE_MAXSIZE and CCACHE_DIR environment variables, respectively, allow you to change the size and location of the cache that Ccache maintains.
Download the Compiler Now
How to install ccache
Use C, C++, or C++ with SYCL code to benefit from Ccache and numerous other capabilities.
Try it
With the Intel oneAPI DPC++/C++ Compiler, which may be purchased separately or as a component of the Intel oneAPI Toolkits, you can increase the efficiency of your program development. The source code is also accessible.
About
A compiler cache is called ccache. By identifying whether the same compilation is being performed again and caching prior compositions, it expedites recompilation. The GNU General Public License, version 3 or later, governs the use of Ccache as free software.
Features
- Compilers such as GCC, Clang, and MSVC (Microsoft Visual C++) are supported.
- Compatible with Windows, Linux, macOS, and other Unix-like operating systems.
- Comprehends CUDA, Objective-C, Objective-C++, C, and C++.
- Allows for optional data sharding into a server cluster and supports remote caching via HTTP (e.g., using Nginx or Google Cloud Storage), Redis, or NFS.
- Fast “direct” and “depend” modes that don’t require the preprocessor are supported.
- Avoids repeatedly hashing the same header files during a build by using an inode cache (on supported OSes and file systems).
- Supports Zstandard compression.
- XXH3 is used to checksum cache content in order to identify data corruption.
- Maintains hit/miss statistics.
- Automatic control of cache size.
- Installation is simple.
- Minimal overhead.
- Rewriting absolute paths to relative ones is supported in order to improve the cache hit ratio.
- When feasible, employ file cloning (also known as “reflinks”) to prevent copies.
- When feasible, employ hard links to prevent copies.
Limitations
- Only understands how to cache a single file’s compilation. Other compilation methods, such as linking and multi-file compilation, will automatically revert to using the original compiler.
- It is not possible to use certain compiler flags. Cache will silently switch back to using the actual compiler if such a flag is found.
- A corner case in the quickest mode (also known as the “direct mode”) may cause false positive cache hits. The manual’s disclaimers section lists these and other minor limitations.
Why even bother?
You can most likely gain from ccache if you ever ran make clean; make. For a variety of reasons, developers frequently perform a clean build of a project, which deletes all of the data from your earlier compilations. Recompilation proceeds significantly more quickly when ccache is used.
The fact that builds in other folders use the same cache is another justification for using ccache. Many of the object files in a build directory can likely be pulled from the cache even if they were compiled for a different version or branch of the software if you have many versions or branches stored in various directories.
Using ccache to speed up clean builds carried out by servers or build farms that routinely verify that the code is buildable is the third scenario.
Additionally, users can share the cache, which is quite helpful when using shared compilation servers.
Is it secure?
The ability of a compiler cache to consistently generate the exact same output as the original compiler is its most crucial feature. This includes offering precisely the same object files and compiler warnings that the actual compiler would generate. The speed should be the only indicator that you are utilising ccache.
Naturally, Ccache makes an effort to offer these assurances. But:
- Compilers are targets in motion. Features that ccache cannot anticipate may be introduced by newer compiler versions, and they frequently do. It can be somewhat challenging for Cache to manage compiler behaviours in various situations, particularly when it comes to backward compatibility with legacy compilers.
- A corner case in the quickest mode (also known as the “direct mode”) may cause false positive cache hits. The manual’s disclaimers section lists these and other minor limitations.