1CCACHE(1)                                                            CCACHE(1)
2
3
4

NAME

6       ccache - a fast C/C++ compiler cache
7

SYNOPSIS

9       ccache [ccache options]
10       ccache [KEY=VALUE ...] compiler [compiler options]
11       compiler [compiler options]
12
13       The first form takes options described in COMMAND LINE OPTIONS below.
14       The second form invokes the compiler, optionally using configuration
15       options as KEY=VALUE arguments. In the third form, ccache is
16       masquerading as the compiler as described in RUN MODES.
17

DESCRIPTION

19       Ccache is a compiler cache. It speeds up recompilation by caching the
20       result of previous compilations and detecting when the same compilation
21       is being done again.
22
23       Ccache has been carefully written to always produce exactly the same
24       compiler output that you would get without the cache. The only way you
25       should be able to tell that you are using ccache is the speed.
26       Currently known exceptions to this goal are listed under CAVEATS. If
27       you discover an undocumented case where ccache changes the output of
28       your compiler, please let us know.
29

RUN MODES

31       There are two different ways to use ccache to cache a compilation:
32
33        1. Prefix your compilation command with ccache. This method is most
34           convenient if you just want to try out ccache or wish to use it for
35           some specific projects. Example:
36
37               ccache gcc -c example.c
38
39        2. Let ccache masquerade as the compiler. This method is most useful
40           when you wish to use ccache for all your compilations. To do this,
41           create a symbolic link to ccache named as the compiler. For
42           example, here is set up ccache to masquerade as gcc and g++:
43
44               cp ccache /usr/local/bin/
45               ln -s ccache /usr/local/bin/gcc
46               ln -s ccache /usr/local/bin/g++
47
48           On platforms that don’t support symbolic links you can simply copy
49           ccache to the compiler name instead for a similar effect:
50
51               cp ccache /usr/local/bin/gcc
52               cp ccache /usr/local/bin/g++
53
54           And so forth. This will work as long as the directory with symbolic
55           links or ccache copies comes before the directory with the compiler
56           (typically /usr/bin) in PATH.
57
58               Warning
59               The technique of letting ccache masquerade as the compiler
60               works well, but currently doesn’t interact well with other
61               tools that do the same thing. See USING CCACHE WITH OTHER
62               COMPILER WRAPPERS.
63

COMMAND LINE OPTIONS

65       These command line options only apply when you invoke ccache as
66       “ccache”. When ccache masquerades as a compiler (as described in the
67       previous section), the normal compiler options apply and you should
68       refer to the compiler’s documentation.
69
70   Common options
71       -c, --cleanup
72           Clean up the cache by removing not recently used cached files until
73           the specified file number and cache size limits are not exceeded.
74           This also recalculates the cache file count and size totals.
75           Normally, there is no need to initiate cleanup manually as ccache
76           keeps the cache below the specified limits at runtime and keeps
77           statistics up to date on each compilation. Forcing a cleanup is
78           mostly useful if you have modified the cache contents manually or
79           believe that the cache size statistics may be inaccurate.
80
81       -C, --clear
82           Clear the entire cache, removing all cached files, but keeping the
83           configuration file.
84
85       --config-path PATH
86           Let the command line options operate on configuration file PATH
87           instead of the default. Using this option has the same effect as
88           setting (overriding) the environment variable CCACHE_CONFIGPATH
89           temporarily.
90
91       -d, --dir PATH
92           Let the command line options operate on cache directory PATH
93           instead of the default. For example, to show statistics for a cache
94           directory at /shared/ccache you can run ccache -d /shared/ccache
95           -s. Using this option has the same effect as setting the
96           environment variable CCACHE_DIR temporarily.
97
98       --evict-namespace NAMESPACE
99           Remove files created in the given namespace from the cache.
100
101       --evict-older-than AGE
102           Remove files used less recently than AGE from the cache. AGE should
103           be an unsigned integer with a d (days) or s (seconds) suffix. If
104           combined with --evict-namespace, only remove files within that
105           namespace.
106
107       -h, --help
108           Print a summary of command line options.
109
110       -F NUM, --max-files NUM
111           Set the maximum number of files allowed in the cache to NUM. Use 0
112           for no limit. The value is stored in a configuration file in the
113           cache directory and applies to all future compilations.
114
115       -M SIZE, --max-size SIZE
116           Set the maximum size of the files stored in the cache. SIZE should
117           be a number followed by an optional suffix: kB, MB, GB, TB
118           (decimal), KiB, MiB, GiB or TiB (binary). The default suffix is
119           GiB. Use 0 for no limit. The value is stored in a configuration
120           file in the cache directory and applies to all future compilations.
121
122       -X LEVEL, --recompress LEVEL
123           Recompress the cache to level LEVEL using the Zstandard algorithm.
124           The level can be an integer, with the same semantics as the
125           compression_level configuration option, or the special value
126           uncompressed for no compression. See [Cache compression] for more
127           information. This can potentially take a long time since all files
128           in the cache need to be visited. Only files that are currently
129           compressed with a different level than LEVEL will be recompressed.
130
131       --recompress-threads THREADS
132           Use up to THREADS threads when recompressing the cache. The default
133           is to use one thread per CPU.
134
135       -o KEY=VALUE, --set-config KEY=VALUE
136           Set configuration option KEY to VALUE. See CONFIGURATION for more
137           information.
138
139       -x, --show-compression
140           Print cache compression statistics. See CACHE COMPRESSION for more
141           information. This can potentially take a long time since all files
142           in the cache need to be visited.
143
144       -p, --show-config
145           Print current configuration options and from where they originate
146           (environment variable, configuration file or compile-time default)
147           in human-readable format.
148
149       --show-log-stats
150           Print statistics counters from the stats log in human-readable
151           format. See stats_log. Use -v/--verbose once or twice for more
152           details.
153
154       -s, --show-stats
155           Print a summary of configuration and statistics counters in
156           human-readable format. Use -v/--verbose once or twice for more
157           details.
158
159       -v, --verbose
160           Increase verbosity. The option can be given multiple times.
161
162       -V, --version
163           Print version and copyright information.
164
165       -z, --zero-stats
166           Zero the cache statistics (but not the configuration options).
167
168   Options for remote file-based storage
169       --trim-dir PATH
170           Remove not recently used files from directory PATH until it is at
171           most the size specified by --trim-max-size.
172
173               Warning
174               Don’t use this option to trim the local cache. To trim the
175               local cache directory to a certain size, use
176               CCACHE_MAXSIZE=SIZE ccache -c.
177
178       --trim-max-size SIZE
179           Specify the maximum size for --trim-dir. SIZE should be a number
180           followed by an optional suffix: kB, MB, GB, TB (decimal), KiB, MiB,
181           GiB or TiB (binary). The default suffix is GiB. Use 0 for no limit.
182
183       --trim-method METHOD
184           Specify the method to trim a directory with --trim-dir. Possible
185           values are:
186
187           atime
188               LRU (least recently used) using the file access timestamp. This
189               is the default.
190
191           mtime
192               LRU (least recently used) using the file modification
193               timestamp.
194
195       --trim-recompress LEVEL
196           Recompress to level LEVEL using the Zstandard algorithm when using
197           --trim-dir. The level can be an integer, with the same semantics as
198           the compression_level configuration option, or the special value
199           uncompressed for no compression. See [Cache compression] for more
200           information. This can potentially take a long time since all files
201           in the cache need to be visited. Only files that are currently
202           compressed with a different level than LEVEL will be recompressed.
203
204       --trim-recompress-threads THREADS
205           Recompress using up to THREADS threads with --trim-recompress. The
206           default is to use one thread per CPU.
207
208   Options for scripting or debugging
209       --checksum-file PATH
210           Print the checksum (128 bit XXH3) of the file at PATH (- for
211           standard input).
212
213       --extract-result PATH
214           Extract data stored in the result file at PATH (- for standard
215           input). The data will be written to ccache-result.* files in to the
216           current working directory. This option is only useful when
217           debugging ccache and its behavior.
218
219       -k KEY, --get-config KEY
220           Print the value of configuration option KEY. See CONFIGURATION for
221           more information.
222
223       --hash-file PATH
224           Print the hash (160 bit BLAKE3) of the file at PATH (- for standard
225           input). This is only useful when debugging ccache and its behavior.
226
227       --inspect PATH
228           Print the content of a result or manifest file at PATH (- for
229           standard input) to standard output in human-readable format. File
230           content embedded in a result file will however not be printed; use
231           --extract-result to extract the file content. This option is only
232           useful when debugging ccache and its behavior.
233
234       --print-stats
235           Print statistics counter IDs and corresponding values in
236           machine-parsable (tab-separated) format.
237
238   Extra options
239       When run as a compiler, ccache usually just takes the same command line
240       options as the compiler you are using. The only exception to this is
241       the option --ccache-skip. That option can be used to tell ccache to
242       avoid interpreting the next option in any way and to pass it along to
243       the compiler as-is.
244
245           Note
246           --ccache-skip currently only tells ccache not to interpret the next
247           option as a special compiler option — the option will still be
248           included in the direct mode hash.
249
250       The reason this can be important is that ccache does need to parse the
251       command line and determine what is an input filename and what is a
252       compiler option, as it needs the input filename to determine the name
253       of the resulting object file (among other things). The heuristic ccache
254       uses when parsing the command line is that any argument that exists as
255       a file is treated as an input file name. By using --ccache-skip you can
256       force an option to not be treated as an input file name and instead be
257       passed along to the compiler as a command line option.
258
259       Another case where --ccache-skip can be useful is if ccache interprets
260       an option specially but shouldn’t, since the option has another meaning
261       for your compiler than what ccache thinks.
262

CONFIGURATION

264       Ccache’s default behavior can be overridden by options in configuration
265       files, which in turn can be overridden by environment variables with
266       names starting with CCACHE_. Ccache normally reads configuration from
267       two files: first a system-level configuration file and secondly a
268       cache-specific configuration file. The priorities of configuration
269       options are as follows (where 1 is highest):
270
271        1. Command line settings in KEY=VALUE form. Example:
272
273               ccache debug=true compiler_check="%compiler% --version" gcc -c example.c
274
275        2. Environment variables.
276
277        3. The cache-specific configuration file (see below).
278
279        4. The system (read-only) configuration file <sysconfdir>/ccache.conf
280           (typically /etc/ccache.conf or /usr/local/etc/ccache.conf).
281
282        5. Compile-time defaults.
283
284       As a special case, if the environment variable CCACHE_CONFIGPATH is set
285       it specifies the configuration file, and the system configuration file
286       won’t be read.
287
288   Location of the configuration file
289       The location of the cache-specific configuration file is determined
290       like this on non-Windows systems:
291
292        1. If CCACHE_CONFIGPATH is set, use that path.
293
294        2. Otherwise, if the environment variable CCACHE_DIR is set then use
295           $CCACHE_DIR/ccache.conf.
296
297        3. Otherwise, if cache_dir is set in the system configuration file
298           then use <cache_dir>/ccache.conf.
299
300        4. Otherwise, if there is a legacy $HOME/.ccache directory then use
301           $HOME/.ccache/ccache.conf.
302
303        5. Otherwise, if XDG_CONFIG_HOME is set then use
304           $XDG_CONFIG_HOME/ccache/ccache.conf.
305
306        6. Otherwise, use $HOME/Library/Preferences/ccache/ccache.conf (macOS)
307           or $HOME/.config/ccache/ccache.conf (other systems).
308
309       On Windows, this is the method used to find the configuration file:
310
311        1. If CCACHE_CONFIGPATH is set, use that path.
312
313        2. Otherwise, if the environment variable CCACHE_DIR is set then use
314           %CCACHE_DIR%/ccache.conf.
315
316        3. Otherwise, if cache_dir is set in the system configuration file
317           then use <cache_dir>\ccache.conf. The system-wide configuration on
318           Windows is %ALLUSERSPROFILE%\ccache\ccache.conf by default. The
319           ALLUSERSPROFILE environment variable is usually C:\ProgramData.
320
321        4. Otherwise, if there is a legacy %USERPROFILE%\.ccache directory
322           then use %USERPROFILE%\.ccache\ccache.conf.
323
324        5. Otherwise, use %LOCALAPPDATA%\ccache\ccache.conf if it exists.
325
326        6. Otherwise, use %APPDATA%\ccache\ccache.conf.
327
328       See also the cache_dir configuration option for how the cache directory
329       location is determined.
330
331   Configuration file syntax
332       Configuration files are in a simple “key = value” format, one option
333       per line. Lines starting with a hash sign are comments. Blank lines are
334       ignored, as is whitespace surrounding keys and values. Example:
335
336           # Set maximum cache size to 10 GB:
337           max_size = 10G
338
339   Boolean values
340       Some configuration options are boolean values (i.e. truth values). In a
341       configuration file, such values must be set to the string true or
342       false. For the corresponding environment variables, the semantics are a
343       bit different:
344
345       •   A set environment variable means “true” (even if set to the empty
346           string).
347
348       •   The following case-insensitive negative values are considered an
349           error (instead of surprising the user): 0, false, disable and no.
350
351       •   An unset environment variable means “false”.
352
353       Each boolean environment variable also has a negated form starting with
354       CCACHE_NO. For example, CCACHE_COMPRESS can be set to force compression
355       and CCACHE_NOCOMPRESS can be set to force no compression.
356
357   Configuration options
358       Below is a list of available configuration options. The corresponding
359       environment variable name is indicated in parentheses after each
360       configuration option key.
361
362       absolute_paths_in_stderr (CCACHE_ABSSTDERR)
363           This option specifies whether ccache should rewrite relative paths
364           in the compiler’s standard error output to absolute paths. This can
365           be useful if you use base_dir with a build system (e.g. CMake with
366           the "Unix Makefiles" generator) that executes the compiler in a
367           different working directory, which makes relative paths in compiler
368           errors or warnings incorrect. The default is false.
369
370       base_dir (CCACHE_BASEDIR)
371           This option should be an absolute path to a directory. If set,
372           ccache will rewrite absolute paths into paths relative to the
373           current working directory, but only absolute paths that begin with
374           base_dir. Cache results can then be shared for compilations in
375           different directories even if the project uses absolute paths in
376           the compiler command line. See also the discussion under COMPILING
377           IN DIFFERENT DIRECTORIES. If set to the empty string (which is the
378           default), no rewriting is done.
379
380           A typical path to use as base_dir is your home directory or another
381           directory that is a parent of your project directories. Don’t use /
382           as the base directory since that will make ccache also rewrite
383           paths to system header files, which typically is contraproductive.
384
385           For example, say that Alice’s current working directory is
386           /home/alice/project1/build and that she compiles like this:
387
388               ccache gcc -I/usr/include/example -I/home/alice/project2/include -c /home/alice/project1/src/example.c
389
390           Here is what ccache will actually execute for different base_dir
391           values:
392
393               # Current working directory: /home/alice/project1/build
394
395               # With base_dir = /:
396               gcc -I../../../../usr/include/example -I../../project2/include -c ../src/example.c
397
398               # With base_dir = /home or /home/alice:
399               gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
400
401               # With base_dir = /home/alice/project1 or /home/alice/project1/src:
402               gcc -I/usr/include/example -I/home/alice/project2/include -c ../src/example.c
403
404           If Bob has put project1 and project2 in /home/bob/stuff and both
405           users have set base_dir to /home or /home/$USER, then Bob will get
406           a cache hit (if they share ccache directory) since the actual
407           command line will be identical to that of Alice:
408
409               # Current working directory: /home/bob/stuff/project1/build
410
411               # With base_dir = /home or /home/bob:
412               gcc -I/usr/include/example -I../../project2/include -c ../src/example.c
413
414           Without base_dir there will be a cache miss since the absolute
415           paths will differ. With base_dir set to / there will be a cache
416           miss since the relative path to /usr/include/example will be
417           different. With base_dir set to /home/bob/stuff/project1 there will
418           a cache miss since the path to project2 will be a different
419           absolute path.
420
421               Warning
422               Rewriting absolute paths to relative is kind of a brittle hack.
423               It works OK in many cases, but there might be cases where
424               things break. One known issue is that absolute paths are not
425               reproduced in dependency files, which can mess up dependency
426               detection in tools like Make and Ninja. If possible, use
427               relative paths in the first place instead instead of using
428               base_dir.
429
430       cache_dir (CCACHE_DIR)
431           This option specifies where ccache will keep its cached compiler
432           outputs.
433
434           On non-Windows systems, the default is $HOME/.ccache if such a
435           directory exists, otherwise $XDG_CACHE_HOME/ccache if
436           XDG_CACHE_HOME is set, otherwise $HOME/Library/Caches/ccache
437           (macOS) or $HOME/.config/ccache (other systems).
438
439           On Windows, the default is %USERPROFILE%\.ccache if such a
440           directory exists, otherwise %LOCALAPPDATA%\ccache.
441
442               Warning
443               Previous ccache versions defaulted to storing the cache in
444               %APPDATA%\ccache on Windows. This can result in large network
445               file transfers of the cache in domain environments and similar
446               problems. Please check this directory for cache directories and
447               either delete them or the whole directory, or move them to the
448               %LOCALAPPDATA%\ccache directory.
449
450           See also Location of the configuration file.
451
452       compiler (CCACHE_COMPILER or (deprecated) CCACHE_CC)
453           This option can be used to force the name of the compiler to use.
454           If set to the empty string (which is the default), ccache works it
455           out from the command line.
456
457       compiler_check (CCACHE_COMPILERCHECK)
458           By default, ccache includes the modification time (“mtime”) and
459           size of the compiler in the hash to ensure that results retrieved
460           from the cache are accurate. If compiler plugins are used, these
461           plugins will also be added to the hash. This option can be used to
462           select another strategy. Possible values are:
463
464           content
465               Hash the content of the compiler binary. This makes ccache very
466               slightly slower compared to mtime, but makes it cope better
467               with compiler upgrades during a build bootstrapping process.
468
469           mtime
470               Hash the compiler’s mtime and size, which is fast. This is the
471               default.
472
473           none
474               Don’t hash anything. This may be good for situations where you
475               can safely use the cached results even though the compiler’s
476               mtime or size has changed (e.g. if the compiler is built as
477               part of your build system and the compiler’s source has not
478               changed, or if the compiler only has changes that don’t affect
479               code generation). You should only use none if you know what you
480               are doing.
481
482           string:value
483               Hash value. This can for instance be a compiler revision number
484               or another string that the build system generates to identify
485               the compiler.
486
487           a command string
488               Hash the standard output and standard error output of the
489               specified command. The string will be split on whitespace to
490               find out the command and arguments to run. No other
491               interpretation of the command string will be done, except that
492               the special word %compiler% will be replaced with the path to
493               the compiler. Several commands can be specified with semicolon
494               as separator. Examples:
495
496                   %compiler% -v
497
498                   %compiler% -dumpmachine; %compiler% -dumpversion
499
500               You should make sure that the specified command is as fast as
501               possible since it will be run once for each ccache invocation.
502
503               Identifying the compiler using a command is useful if you want
504               to avoid cache misses when the compiler has been rebuilt but
505               not changed.
506
507               Another case is when the compiler (as seen by ccache) actually
508               isn’t the real compiler but another compiler wrapper — in that
509               case, the default mtime method will hash the mtime and size of
510               the other compiler wrapper, which means that ccache won’t be
511               able to detect a compiler upgrade. Using a suitable command to
512               identify the compiler is thus safer, but it’s also slower, so
513               you should consider continue using the mtime method in
514               combination with the prefix_command option if possible. See
515               USING CCACHE WITH OTHER COMPILER WRAPPERS.
516
517       compiler_type (CCACHE_COMPILERTYPE)
518           Ccache normally guesses the compiler type based on the compiler
519           name. The compiler_type option lets you force a compiler type. This
520           can be useful if the compiler has a non-standard name but is
521           actually one of the known compiler types. Possible values are:
522
523           auto
524               Guess one of the types below based on the compiler name
525               (following symlinks). This is the default.
526
527           clang
528               Clang-based compiler.
529
530           clang-cl
531               clang-cl.
532
533           gcc
534               GCC-based compiler.
535
536           icl
537               Intel compiler on Windows.
538
539           msvc
540               Microsoft Visual C++ (MSVC).
541
542           nvcc
543               NVCC (CUDA) compiler.
544
545           other
546               Any compiler other than the known types.
547
548       compression (CCACHE_COMPRESS or CCACHE_NOCOMPRESS, see Boolean values
549       above)
550           If true, ccache will compress data it puts in the cache. However,
551           this option has no effect on how files are retrieved from the
552           cache; compressed and uncompressed results will still be usable
553           regardless of this option. The default is true.
554
555           Compression is done using the Zstandard algorithm. The algorithm is
556           fast enough that there should be little reason to turn off
557           compression to gain performance. One exception is if the cache is
558           located on a compressed file system, in which case the compression
559           performed by ccache of course is redundant.
560
561           Compression will be disabled if file cloning (the file_clone
562           option) or hard linking (the hard_link option) is enabled.
563
564       compression_level (CCACHE_COMPRESSLEVEL)
565           This option determines the level at which ccache will compress
566           object files using the real-time compression algorithm Zstandard.
567           It only has effect if compression is enabled (which it is by
568           default). Zstandard is extremely fast for decompression and very
569           fast for compression for lower compression levels. The default is
570           0.
571
572           Semantics of compression_level:
573
574           > 0
575               A positive value corresponds to normal Zstandard compression
576               levels. Lower levels (e.g. 1) mean faster compression but worse
577               compression ratio. Higher levels (e.g. 19) mean slower
578               compression but better compression ratio. The maximum possible
579               value depends on the libzstd version, but at least up to 19 is
580               available for all versions. Decompression speed is essentially
581               the same for all levels. As a rule of thumb, use level 5 or
582               lower since higher levels may slow down compilations
583               noticeably. Higher levels are however useful when recompressing
584               the cache with command line option -X/--recompress.
585
586           < 0
587               A negative value corresponds to Zstandard’s “ultra-fast”
588               compression levels, which are even faster than level 1 but with
589               less good compression ratios. For instance, level -3
590               corresponds to --fast=3 for the zstd command line tool. In
591               practice, there is little use for levels lower than -5 or so.
592
593           0 (default)
594               The value 0 means that ccache will choose a suitable level,
595               currently 1.
596
597           See the Zstandard documentation <http://zstd.net> for more
598           information.
599
600       cpp_extension (CCACHE_EXTENSION)
601           This option can be used to force a certain extension for the
602           intermediate preprocessed file. The default is to automatically
603           determine the extension to use for intermediate preprocessor files
604           based on the type of file being compiled, but that sometimes
605           doesn’t work. For example, when using the “aCC” compiler on HP-UX,
606           set the cpp extension to i.
607
608       debug (CCACHE_DEBUG or CCACHE_NODEBUG, see Boolean values above)
609           If true, enable the debug mode. The debug mode creates per-object
610           debug files that are helpful when debugging unexpected cache
611           misses. Note however that ccache performance will be reduced
612           slightly. See CACHE DEBUGGING for more information. The default is
613           false.
614
615       debug_dir (CCACHE_DEBUGDIR)
616           Specifies where to write per-object debug files if the debug mode
617           is enabled. If set to the empty string, the files will be written
618           next to the object file. If set to a directory, the debug files
619           will be written with full absolute paths in that directory,
620           creating it if needed. The default is the empty string.
621
622           For example, if debug_dir is set to /example, the current working
623           directory is /home/user and the object file is build/output.o then
624           the debug log will be written to
625           /example/home/user/build/output.o.ccache-log. See also CACHE
626           DEBUGGING.
627
628       depend_mode (CCACHE_DEPEND or CCACHE_NODEPEND, see Boolean values
629       above)
630           If true, the depend mode will be used. The default is false. See
631           The depend mode.
632
633       direct_mode (CCACHE_DIRECT or CCACHE_NODIRECT, see Boolean values
634       above)
635           If true, the direct mode will be used. The default is true. See The
636           direct mode.
637
638       disable (CCACHE_DISABLE or CCACHE_NODISABLE, see Boolean values above)
639           When true, ccache will just call the real compiler, bypassing the
640           cache completely. The default is false.
641
642           It is also possible to disable ccache for a specific source code
643           file by adding the string ccache:disable in a comment in the first
644           4096 bytes of the file.
645
646       extra_files_to_hash (CCACHE_EXTRAFILES)
647           This option is a list of paths to files that ccache will include in
648           the the hash sum that identifies the build. The list separator is
649           semicolon on Windows systems and colon on other systems.
650
651       file_clone (CCACHE_FILECLONE or CCACHE_NOFILECLONE, see Boolean values
652       above)
653           If true, ccache will attempt to use file cloning (also known as
654           “copy on write”, “CoW” or “reflinks”) to store and fetch cached
655           compiler results. file_clone has priority over hard_link. The
656           default is false.
657
658           Files stored by cloning cannot be compressed, so the cache size
659           will likely be significantly larger if this option is enabled.
660           However, performance may be improved depending on the use case.
661
662           Unlike the hard_link option, file_clone is completely safe to use,
663           but not all file systems support the feature. For such file
664           systems, ccache will fall back to use plain copying (or hard links
665           if hard_link is enabled).
666
667       hard_link (CCACHE_HARDLINK or CCACHE_NOHARDLINK, see Boolean values
668       above)
669           If true, ccache will attempt to use hard links to store and fetch
670           cached object files. The default is false.
671
672           Files stored via hard links cannot be compressed, so the cache size
673           will likely be significantly larger if this option is enabled.
674           However, performance may be improved depending on the use case.
675
676               Warning
677               Do not enable this option unless you are aware of these
678               caveats:
679
680           •   If the resulting file is modified, the file in the cache will
681               also be modified since they share content, which corrupts the
682               cache entry. As of version 4.0, ccache makes stored and fetched
683               object files read-only as a safety measure. Furthermore, a
684               simple integrity check is made for cached object files by
685               verifying that their sizes are correct. This means that
686               mistakes like strip file.o or echo >file.o will be detected
687               even if the object file is made writable, but a modification
688               that doesn’t change the file size will not.
689
690           •   Programs that don’t expect that files from two different
691               identical compilations are hard links to each other can fail.
692
693           •   Programs that rely on modification times (like make) can be
694               confused if several users (or one user with several build
695               trees) use the same cache directory. The reason for this is
696               that the object files share i-nodes and therefore modification
697               times. If file.o is in build tree A (hard-linked from the
698               cache) and file.o then is produced by ccache in build tree B by
699               hard-linking from the cache, the modification timestamp will be
700               updated for file.o in build tree A as well. This can retrigger
701               relinking in build tree A even though nothing really has
702               changed.
703
704       hash_dir (CCACHE_HASHDIR or CCACHE_NOHASHDIR, see Boolean values above)
705           If true (which is the default), ccache will include the current
706           working directory (CWD) in the hash that is used to distinguish two
707           compilations when generating debug info (compiler option -g with
708           variations). Exception: The CWD will not be included in the hash if
709           base_dir is set (and matches the CWD) and the compiler option
710           -fdebug-prefix-map is used. See also the discussion under COMPILING
711           IN DIFFERENT DIRECTORIES.
712
713           The reason for including the CWD in the hash by default is to
714           prevent a problem with the storage of the current working directory
715           in the debug info of an object file, which can lead ccache to
716           return a cached object file that has the working directory in the
717           debug info set incorrectly.
718
719           You can disable this option to get cache hits when compiling the
720           same source code in different directories if you don’t mind that
721           CWD in the debug info might be incorrect.
722
723       ignore_headers_in_manifest (CCACHE_IGNOREHEADERS)
724           This option is a list of paths to files (or directories with
725           headers) that ccache will not include in the manifest list that
726           makes up the direct mode. Note that this can cause stale cache hits
727           if those headers do indeed change. The list separator is semicolon
728           on Windows systems and colon on other systems.
729
730       ignore_options (CCACHE_IGNOREOPTIONS)
731           This option is a space-delimited list of compiler options that
732           ccache will exclude from the hash. Excluding a compiler option from
733           the hash can be useful when you know it doesn’t affect the result
734           (but ccache doesn’t know that), or when it does and you don’t care.
735           If a compiler option in the list is suffixed with an asterisk (*)
736           it will be matched as a prefix. For example, -fmessage-length=*
737           will match both -fmessage-length=20 and -fmessage-length=70.
738
739       inode_cache (CCACHE_INODECACHE or CCACHE_NOINODECACHE, see Boolean
740       values above)
741           If true, ccache will cache source file hashes based on device,
742           inode and timestamps. This reduces the time spent on hashing
743           include files since the result can be reused between compilations.
744           The default is true. The feature requires temporary_dir to be
745           located on a local filesystem of a supported type.
746
747               Note
748               The inode cache feature is currently not available on Windows.
749
750       keep_comments_cpp (CCACHE_COMMENTS or CCACHE_NOCOMMENTS, see Boolean
751       values above)
752           If true, ccache will not discard the comments before hashing
753           preprocessor output. The default is false. This can be used to
754           check documentation with -Wdocumentation.
755
756       log_file (CCACHE_LOGFILE)
757           If set to a file path, ccache will write information on what it is
758           doing to the specified file. This is useful for tracking down
759           problems.
760
761           If set to syslog, ccache will log using syslog() instead of to a
762           file. If you use rsyslogd, you can add something like this to
763           /etc/rsyslog.conf or a file in /etc/rsyslog.d:
764
765               # log ccache to file
766               :programname, isequal, "ccache"         /var/log/ccache
767               # remove from syslog
768               & ~
769
770       max_files (CCACHE_MAXFILES)
771           This option specifies the maximum number of files to keep in the
772           cache. Use 0 for no limit (which is the default). See also CACHE
773           SIZE MANAGEMENT.
774
775       max_size (CCACHE_MAXSIZE)
776           This option specifies the maximum size of the cache. Use 0 for no
777           limit. The default value is 5G. Available suffixes: k, M, G, T
778           (decimal) and Ki, Mi, Gi, Ti (binary). The default suffix is G. See
779           also CACHE SIZE MANAGEMENT.
780
781       msvc_dep_prefix (CCACHE_MSVC_DEP_PREFIX)
782           This option specifies the prefix of included files output for MSVC
783           compiler. The default prefix is “Note: including file:”. If you use
784           a localized compiler, this should be set accordingly.
785
786       namespace (CCACHE_NAMESPACE)
787           If set, the namespace string will be added to the hashed data for
788           each compilation. This will make the associated cache entries
789           logically separate from cache entries with other namespaces, but
790           they will still share the same storage space. Cache entries can
791           also be selectively removed from the local cache with the command
792           line option --evict-namespace, potentially in combination with
793           --evict-older-than.
794
795           For instance, if you use the same local cache for several disparate
796           projects, you can use a unique namespace string for each one. This
797           allows you to remove cache entries that belong to a certain project
798           if you stop working with that project.
799
800       path (CCACHE_PATH)
801           If set, ccache will search directories in this list when looking
802           for the real compiler. The list separator is semicolon on Windows
803           systems and colon on other systems. If not set, ccache will look
804           for the first executable matching the compiler name in the normal
805           PATH that isn’t a symbolic link to ccache itself.
806
807       pch_external_checksum (CCACHE_PCH_EXTSUM or CCACHE_NOPCH_EXTSUM, see
808       Boolean values above)
809           When this option is set, and ccache finds a precompiled header
810           file, ccache will look for a file with the extension “.sum” added
811           (e.g. “pre.h.gch.sum”), and if found, it will hash this file
812           instead of the precompiled header itself to work around the
813           performance penalty of hashing very large files.
814
815       prefix_command (CCACHE_PREFIX)
816           This option adds a list of prefixes (separated by space) to the
817           command line that ccache uses when invoking the compiler. See also
818           USING CCACHE WITH OTHER COMPILER WRAPPERS.
819
820       prefix_command_cpp (CCACHE_PREFIX_CPP)
821           This option adds a list of prefixes (separated by space) to the
822           command line that ccache uses when invoking the preprocessor.
823
824       read_only (CCACHE_READONLY or CCACHE_NOREADONLY, see Boolean values
825       above)
826           If true, ccache will attempt to use existing cached results, but it
827           will not add new results to any cache backend. Statistics counters
828           will still be updated, though, unless the stats option is set to
829           false.
830
831           If you are using this because your ccache directory is read-only,
832           you need to set temporary_dir since ccache will fail to create
833           temporary files otherwise. You may also want to set stats to false
834           make ccache not even try to update stats files.
835
836       read_only_direct (CCACHE_READONLY_DIRECT or CCACHE_NOREADONLY_DIRECT,
837       see Boolean values above)
838           Just like read_only except that ccache will only try to retrieve
839           results from the cache using the direct mode, not the preprocessor
840           mode. See documentation for read_only regarding using a read-only
841           ccache directory.
842
843       recache (CCACHE_RECACHE or CCACHE_NORECACHE, see Boolean values above)
844           If true, ccache will not use any previously stored result. New
845           results will still be cached, possibly overwriting any pre-existing
846           results.
847
848       remote_only (CCACHE_REMOTE_ONLY or CCACHE_NOREMOTE_ONLY, see Boolean
849       values above)
850           If true, ccache will only use remote storage. The default is false.
851           Note that cache statistics counters will still be kept in the local
852           cache directory unless stats is false. See also Storage
853           interaction.
854
855       remote_storage (CCACHE_REMOTE_STORAGE)
856           This option specifies one or several storage backends (separated by
857           space) to query after checking the local cache (unless remote_only
858           is true). See REMOTE STORAGE BACKENDS for documentation of syntax
859           and available backends.
860
861           Examples:
862
863file:/shared/nfs/directory
864
865file:///shared/nfs/one|read-only file:///shared/nfs/two
866
867file:///Z:/example/windows/folder
868
869http://example.com/cache
870
871redis://example.com
872
873                   Note
874                   In previous ccache versions this option was called
875                   secondary_storage (CCACHE_SECONDARY_STORAGE), which can
876                   still be used as an alias.
877
878       reshare (CCACHE_RESHARE or CCACHE_NORESHARE, see Boolean values above)
879           If true, ccache will write results to remote storage even for local
880           storage cache hits. The default is false.
881
882       run_second_cpp (CCACHE_CPP2 or CCACHE_NOCPP2, see Boolean values above)
883           If true, ccache will first run the preprocessor to preprocess the
884           source code (see The preprocessor mode) and then on a cache miss
885           run the compiler on the source code to get hold of the object file.
886           This is the default.
887
888           If false, ccache will first run preprocessor to preprocess the
889           source code and then on a cache miss run the compiler on the
890           preprocessed source code instead of the original source code. This
891           makes cache misses slightly faster since the source code only has
892           to be preprocessed once. The downside is that some compilers won’t
893           produce the same result (for instance diagnostics warnings) when
894           compiling preprocessed source code.
895
896           A solution to the above mentioned downside is to set run_second_cpp
897           to false and pass -fdirectives-only (for GCC) or -frewrite-includes
898           (for Clang) to the compiler. This will cause the compiler to leave
899           the macros and other preprocessor information, and only process the
900           #include directives. When run in this way, the preprocessor
901           arguments will be passed to the compiler since it still has to do
902           some preprocessing (like macros).
903
904           This option is ignored with MSVC, as there is no way to make it
905           compile without preprocessing first.
906
907       sloppiness (CCACHE_SLOPPINESS)
908           By default, ccache tries to give as few false cache hits as
909           possible. However, in certain situations it’s possible that you
910           know things that ccache can’t take for granted. This option makes
911           it possible to tell ccache to relax some checks in order to
912           increase the hit rate. The value should be a comma-separated string
913           with one or several of the following values:
914
915           clang_index_store
916               Ignore the Clang compiler option -index-store-path and its
917               argument when computing the manifest hash. This is useful if
918               you use Xcode, which uses an index store path derived from the
919               local project path. Note that the index store won’t be updated
920               correctly on cache hits if you enable this sloppiness.
921
922           file_stat_matches
923               Ccache normally examines a file’s contents to determine whether
924               it matches the cached version. With this sloppiness set, ccache
925               will consider a file as matching its cached version if the
926               mtimes and ctimes match.
927
928           file_stat_matches_ctime
929               Ignore ctimes when file_stat_matches is enabled. This can be
930               useful when backdating files' mtimes in a controlled way.
931
932           gcno_cwd
933               By default, ccache will include the current working directory
934               in the hash when producing a .gcno file (when compiling with
935               -ftest-coverage or --coverage). This is because GCC 9+ includes
936               the current working directory in the .gcno file. The gcno_cwd
937               sloppiness makes ccache not hash the current working directory
938               so that you can get cache hits when compiling in different
939               directories, with the tradeoff of potentially getting an
940               incorrect directory in the .gcno file. gcno_cwd also disables
941               hashing of the current working directory if -fprofile-abs-path
942               is used.
943
944           include_file_ctime
945               By default, ccache will disable the direct mode if an include
946               file has too new ctime. This sloppiness disables that check.
947               See also [Handling of newly created header files].
948
949           include_file_mtime
950               By default, ccache will disable the direct mode if an include
951               file has too new mtime. This sloppiness disables that check.
952               See also [Handling of newly created header files].
953
954           ivfsoverlay
955               Ignore the Clang compiler option -ivfsoverlay and its argument.
956               This is useful if you use Xcode, which uses a virtual file
957               system (VFS) for things like combining Objective-C and Swift
958               code.
959
960           locale
961               Ccache includes the environment variables LANG, LC_ALL,
962               LC_CTYPE and LC_MESSAGES in the hash by default since they may
963               affect localization of compiler warning messages. Set this
964               sloppiness to tell ccache not to do that.
965
966           modules
967               By default, ccache will not cache compilations if -fmodules is
968               used since it cannot hash the state of compiler’s internal
969               representation of relevant modules. This sloppiness allows
970               caching in such a case. See C++ MODULES for more information.
971
972           pch_defines
973               Be sloppy about #define directives when precompiling a header
974               file. See PRECOMPILED HEADERS for more information.
975
976           random_seed
977               Ignore the -frandom-seed option and its arguments when
978               computing the input hash. This is useful if your build system
979               generates different seeds between builds and you are OK with
980               reusing cached results.
981
982           system_headers
983               By default, ccache will also include all system headers in the
984               manifest. With this sloppiness set, ccache will only include
985               system headers in the hash but not add the system header files
986               to the list of include files.
987
988           time_macros
989               Ignore __DATE__, __TIME__ and __TIMESTAMP__ being present in
990               the source code.
991
992           See the discussion under TROUBLESHOOTING for more information.
993
994       stats (CCACHE_STATS or CCACHE_NOSTATS, see Boolean values above)
995           If true, ccache will update the statistics counters on each
996           compilation. The default is true. If false, [automatic cleanup]
997           will be disabled as well.
998
999       stats_log (CCACHE_STATSLOG)
1000           If set to a file path, ccache will write statistics counter updates
1001           to the specified file. This is useful for getting statistics for
1002           individual builds. To show a summary of the current stats log, use
1003           ccache --show-log-stats.
1004
1005               Note
1006               Lines in the stats log starting with a hash sign (#) are
1007               comments.
1008
1009       temporary_dir (CCACHE_TEMPDIR)
1010           This option specifies where ccache will put temporary files. The
1011           default is $XDG_RUNTIME_DIR/ccache-tmp (typically
1012           /run/user/<UID>/ccache-tmp) if XDG_RUNTIME_DIR is set and the
1013           directory exists, otherwise <cache_dir>/tmp.
1014
1015               Note
1016               In previous versions of ccache, CCACHE_TEMPDIR had to be on the
1017               same filesystem as the CCACHE_DIR path, but this requirement
1018               has been relaxed.
1019
1020       umask (CCACHE_UMASK)
1021           This option (an octal integer) specifies the umask for files and
1022           directories in the cache directory. This is mostly useful when you
1023           wish to share your cache with other users.
1024
1025   Disabling ccache
1026       To disable ccache completely for all invocations, set disable = true
1027       (CCACHE_DISABLE=1). You can also disable ccache for a certain source
1028       code file by adding the string ccache:disable in a comment in the first
1029       4096 bytes of the file. In the latter case the Ccache disabled
1030       statistics counter will be increased.
1031

REMOTE STORAGE BACKENDS

1033       The remote_storage option lets you configure ccache to use one or
1034       several remote storage backends. By default, the local cache directory
1035       located in cache_dir will be queried first and remote storage second,
1036       but remote_only can be set to true to disable local storage. Note that
1037       cache statistics counters will still be kept in the local cache
1038       directory — remote storage backends only store compilation results and
1039       manifests.
1040
1041       A remote storage backend is specified with a URL, optionally followed
1042       by a pipe (|) and a pipe-separated list of attributes. An attribute is
1043       key=value or just key as a short form of key=true. Attribute values
1044       must be percent-encoded
1045       <https://en.wikipedia.org/wiki/Percent-encoding> if they contain
1046       percent, pipe or space characters.
1047
1048   Attributes for all backends
1049       These optional attributes are available for all remote storage
1050       backends:
1051
1052read-only: If true, only read from this backend, don’t write. The
1053           default is false.
1054
1055shards: A comma-separated list of names for sharding (partitioning)
1056           the cache entries using Rendezvous hashing
1057           <https://en.wikipedia.org/wiki/Rendezvous_hashing>, typically to
1058           spread the cache over a server cluster. When set, the storage URL
1059           must contain an asterisk (*), which will be replaced by one of the
1060           shard names to form a real URL. A shard name can optionally have an
1061           appended weight within parentheses to indicate how much of the key
1062           space should be associated with that shard. A shard with weight w
1063           will contain w/S of the cache, where S is the sum of all shard
1064           weights. A weight could for instance be set to represent the
1065           available memory for a memory cache on a specific server. The
1066           default weight is 1.
1067
1068           Examples:
1069
1070redis://cache-*.example.com|shards=a(3),b(1),c(1.5) will put
1071               55% (3/5.5) of the cache on redis://cache-a.example.com, 18%
1072               (1/5.5) on redis://cache-b.example.com and 27% (1.5/5.5) on
1073               redis://cache-c.example.com.
1074
1075http://example.com/*|shards=alpha,beta will put 50% of the
1076               cache on http://example.com/alpha and 50% on
1077               http://example.com/beta.
1078
1079   Storage interaction
1080       The table below describes the interaction between local and remote
1081       storage on cache hits and misses if remote_only is false (which is the
1082       default):
1083
1084       ┌──────────────┬────────────────┬───────────────────┐
1085       │              │                │                   │
1086Local storage Remote storage What happens      
1087       ├──────────────┼────────────────┼───────────────────┤
1088       │              │                │                   │
1089       │miss          │ miss           │ Compile, write to │
1090       │              │                │ local, write to   │
1091       │              │                │ remote[1]         │
1092       ├──────────────┼────────────────┼───────────────────┤
1093       │              │                │                   │
1094       │miss          │ hit            │ Read from remote, │
1095       │              │                │ write to local    │
1096       ├──────────────┼────────────────┼───────────────────┤
1097       │              │                │                   │
1098       │hit           │ -              │ Read from local,  │
1099       │              │                │ don’t write to    │
1100       │              │                │ remote[2]         │
1101       └──────────────┴────────────────┴───────────────────┘
1102
1103       [1] Unless remote storage has attribute read-only=true.
1104       [2] Unless local storage is set to share its cache hits with the
1105       reshare option.
1106
1107       If remote_only is true:
1108
1109       ┌──────────────┬────────────────┬─────────────────────┐
1110       │              │                │                     │
1111Local storage Remote storage What happens        
1112       ├──────────────┼────────────────┼─────────────────────┤
1113       │              │                │                     │
1114       │-             │ miss           │ Compile, write to   │
1115       │              │                │ remote, don’t write │
1116       │              │                │ to local            │
1117       ├──────────────┼────────────────┼─────────────────────┤
1118       │              │                │                     │
1119       │-             │ hit            │ Read from remote,   │
1120       │              │                │ don’t write to      │
1121       │              │                │ local               │
1122       └──────────────┴────────────────┴─────────────────────┘
1123
1124   File storage backend
1125       URL format: file:DIRECTORY or file://[HOST]DIRECTORY
1126
1127       This backend stores data as separate files in a directory structure
1128       below DIRECTORY, similar (but not identical) to the local cache
1129       storage. A typical use case for this backend would be sharing a cache
1130       on an NFS directory. DIRECTORY must start with a slash. HOST can be the
1131       empty string or localhost. On Windows, HOST can also be the name of a
1132       server hosting a shared folder.
1133
1134           Important
1135           ccache will not perform any cleanup of the storage — that has to be
1136           done by other means, for instance by running ccache --trim-dir
1137           periodically.
1138
1139       Examples:
1140
1141file:/shared/nfs/directory
1142
1143file:///shared/nfs/directory|umask=002|update-mtime=true
1144
1145file:///Z:/example/windows/folder
1146
1147file://example.com/shared/ccache%20folder
1148
1149       Optional attributes:
1150
1151layout: How to store file under the cache directory. Available
1152           values:
1153
1154flat: Store all files directly under the cache directory.
1155
1156subdirs: Store files in 256 subdirectories of the cache
1157               directory.
1158
1159           The default is subdirs.
1160
1161umask: This attribute (an octal integer) overrides the umask to use
1162           for files and directories in the cache directory.
1163
1164update-mtime: If true, update the modification time (mtime) of
1165           cache entries that are read. The default is false.
1166
1167   HTTP storage backend
1168       URL format: http://HOST[:PORT][/PATH]
1169
1170       This backend stores data in an HTTP-compatible server. The required
1171       HTTP methods are GET, PUT and DELETE.
1172
1173           Important
1174           ccache will not perform any cleanup of the storage — that has to be
1175           done by other means, for instance by running ccache --trim-dir
1176           periodically.
1177
1178           Note
1179           HTTPS is not supported.
1180
1181           Tip
1182           See How to set up HTTP storage
1183           <https://ccache.dev/howto/http-storage.html> for hints on how to
1184           set up an HTTP server for use with ccache.
1185
1186       Examples:
1187
1188http://localhost
1189
1190http://someusername:p4ssw0rd@example.com/cache/
1191
1192http://localhost:8080|layout=bazel|connect-timeout=50
1193
1194       Optional attributes:
1195
1196bearer-token: Bearer token used to authorize the HTTP requests.
1197
1198connect-timeout: Timeout (in ms) for network connection. The
1199           default is 100.
1200
1201keep-alive: If true, keep the HTTP connection to the storage server
1202           open to avoid reconnects. The default is true.
1203
1204layout: How to map key names to the path part of the URL. Available
1205           values:
1206
1207bazel: Store values in a format compatible with the Bazel HTTP
1208               caching protocol. More specifically, the entries will be stored
1209               as 64 hex digits under the /ac/ part of the cache.
1210
1211                   Note
1212                   You may have to disable verification of action cache values
1213                   in the server for this to work since ccache entries are not
1214                   valid action result metadata values.
1215
1216flat: Append the key directly to the path part of the URL (with
1217               a leading slash if needed).
1218
1219subdirs: Append the first two characters of the key to the URL
1220               (with a leading slash if needed), followed by a slash and the
1221               rest of the key. This divides the entries into 256 buckets.
1222
1223           The default is subdirs.
1224
1225operation-timeout: Timeout (in ms) for HTTP requests. The default
1226           is 10000.
1227
1228   Redis storage backend
1229       URL formats:
1230
1231       redis://[[USERNAME:]PASSWORD@]HOST[:PORT][/DBNUMBER]
1232       redis+unix:SOCKET_PATH[?db=DBNUMBER]
1233       redis+unix://[[USERNAME:]PASSWORD@localhost]SOCKET_PATH[?db=DBNUMBER]
1234
1235       This backend stores data in a Redis <https://redis.io> (or
1236       Redis-compatible) server. There are implementations for both
1237       memory-based and disk-based storage. PORT defaults to 6379 and DBNUMBER
1238       defaults to 0.
1239
1240           Note
1241           ccache will not perform any cleanup of the Redis storage, but you
1242           can configure LRU eviction <https://redis.io/topics/lru-cache>.
1243
1244           Tip
1245           See How to set up Redis
1246           <https://ccache.dev/howto/redis-storage.html> storage"  for hints
1247           on setting up a Redis server for use with ccache.
1248
1249           Tip
1250           You can set up a cluster of Redis servers using the shards
1251           attribute described in REMOTE STORAGE BACKENDS.
1252
1253       Examples:
1254
1255redis://localhost
1256
1257redis://p4ssw0rd@cache.example.com:6379/0|connect-timeout=50
1258
1259redis+unix:/run/redis.sock
1260
1261redis+unix:///run/redis.sock
1262
1263redis+unix://p4ssw0rd@localhost/run/redis.sock?db=0
1264
1265       Optional attributes:
1266
1267connect-timeout: Timeout (in ms) for network connection. The
1268           default is 100.
1269
1270operation-timeout: Timeout (in ms) for Redis commands. The default
1271           is 10000.
1272

CACHE SIZE MANAGEMENT

1274       By default, ccache has a 5 GB limit on the total size of files in the
1275       cache and no limit on the number of files. You can set different limits
1276       using the command line options -M/--max-size and -F/--max-files. Use
1277       the -s/--show-stats option to see the cache size and the currently
1278       configured limits (in addition to other various statistics).
1279
1280       Cleanup can be triggered in two different ways: automatic and manual.
1281
1282   Automatic cleanup
1283       After a new compilation result has been written to the local cache,
1284       ccache will trigger an automatic cleanup if max_size or max_files is
1285       exceeded. The cleanup removes cache entries in LRU (least recently
1286       used) order based on the modification time (mtime) of files in the
1287       cache. For this reason, ccache updates mtime of the cache files read on
1288       a cache hit to mark them as recently used.
1289
1290   Manual cleanup
1291       You can run ccache -c/--cleanup to force cleanup of the whole cache.
1292       This will recalculate the cache size information and also make sure
1293       that the cache size does not exceed max_size and max_files.
1294

CACHE COMPRESSION

1296       Ccache will by default compress all data it puts into the cache using
1297       the compression algorithm Zstandard <http://zstd.net> (zstd) using
1298       compression level 1. The algorithm is fast enough that there should be
1299       little reason to turn off compression to gain performance. One
1300       exception is if the cache is located on a compressed file system, in
1301       which case the compression performed by ccache of course is redundant.
1302       See the documentation for the configuration options compression and
1303       compression_level for more information.
1304
1305       You can use the command line option -x/--show-compression to print
1306       information related to compression. Example:
1307
1308           Total data:           14.8 GB (16.0 GB disk blocks)
1309           Compressed data:      11.3 GB (30.6% of original size)
1310             Original size:      36.9 GB
1311             Compression ratio: 3.267 x  (69.4% space savings)
1312           Incompressible data:   3.5 GB
1313
1314       Notes:
1315
1316       •   The “disk blocks” size is the cache size when taking disk block
1317           size into account. This value should match the “Cache size” value
1318           from “ccache --show-stats”. The other size numbers refer to actual
1319           content sizes.
1320
1321       •   “Compressed data” refers to result and manifest files stored in the
1322           cache.
1323
1324       •   “Incompressible data” refers to files that are always stored
1325           uncompressed (triggered by enabling file_clone or hard_link) or
1326           unknown files (for instance files created by older ccache
1327           versions).
1328
1329       •   The compression ratio is affected by compression_level.
1330
1331       The cache data can also be recompressed to another compression level
1332       (or made uncompressed) with the command line option -X/--recompress. If
1333       you choose to disable compression by default or to use a low
1334       compression level, you can (re)compress newly cached data with a higher
1335       compression level after the build or at another time when there are
1336       more CPU cycles available, for instance every night. Full recompression
1337       potentially takes a lot of time, but only files that are currently
1338       compressed with a different level than the target level will be
1339       recompressed.
1340

CACHE STATISTICS

1342       ccache --show-stats shows a summary of statistics, including cache
1343       size, cleanups (number of performed cleanups, either implicitly due to
1344       a cache size limit being reached or due to explicit ccache -c calls),
1345       overall hit rate, hit rate for direct/preprocessed modes and hit rate
1346       for local and remote storage.
1347
1348       The summary also includes counters called “Errors” and “Uncacheable”,
1349       which are sums of more detailed counters. To see those detailed
1350       counters, use the -v/--verbose flag. The verbose mode can show the
1351       following counters:
1352
1353       ┌───────────────────────────┬────────────────────────────┐
1354       │                           │                            │
1355Counter                    Description                
1356       ├───────────────────────────┼────────────────────────────┤
1357       │                           │                            │
1358       │Autoconf compile/link      │ Uncacheable compilation or │
1359       │                           │ linking by an Autoconf     │
1360       │                           │ test.                      │
1361       ├───────────────────────────┼────────────────────────────┤
1362       │                           │                            │
1363       │Bad compiler arguments     │ Malformed compiler         │
1364       │                           │ argument, e.g. missing a   │
1365       │                           │ value for a compiler       │
1366       │                           │ option that requires an    │
1367       │                           │ argument or failure to     │
1368       │                           │ read a file specified by a │
1369       │                           │ compiler option argument.  │
1370       ├───────────────────────────┼────────────────────────────┤
1371       │                           │                            │
1372       │Called for linking         │ The compiler was called    │
1373       │                           │ for linking, not           │
1374       │                           │ compiling. Ccache only     │
1375       │                           │ supports compilation of a  │
1376       │                           │ single file, i.e. calling  │
1377       │                           │ the compiler with the -c   
1378       │                           │ option to produce a single │
1379       │                           │ object file from a single  │
1380       │                           │ source file.               │
1381       ├───────────────────────────┼────────────────────────────┤
1382       │                           │                            │
1383       │Called for preprocessing   │ The compiler was called    │
1384       │                           │ for preprocessing, not     │
1385       │                           │ compiling.                 │
1386       ├───────────────────────────┼────────────────────────────┤
1387       │                           │                            │
1388       │Ccache disabled            │ Ccache was disabled by a   │
1389       │                           │ ccache:disable string in   │
1390       │                           │ the source code file.      │
1391       ├───────────────────────────┼────────────────────────────┤
1392       │                           │                            │
1393       │Could not use modules      │ Preconditions for using    │
1394       │                           │ C++ MODULES were not       │
1395       │                           │ fulfilled.                 │
1396       ├───────────────────────────┼────────────────────────────┤
1397       │                           │                            │
1398       │Could not use precompiled  │ Preconditions for using    │
1399       │header                     │ precompiled headers were   │
1400       │                           │ not fulfilled.             │
1401       ├───────────────────────────┼────────────────────────────┤
1402       │                           │                            │
1403       │Could not write to output  │ The output path specified  │
1404       │file                       │ with -o could not be       │
1405       │                           │ written to.                │
1406       ├───────────────────────────┼────────────────────────────┤
1407       │                           │                            │
1408       │Compilation failed         │ The compilation failed. No │
1409       │                           │ result stored in the       │
1410       │                           │ cache.                     │
1411       ├───────────────────────────┼────────────────────────────┤
1412       │                           │                            │
1413       │Compiler check failed      │ A compiler check program   │
1414       │                           │ specified by               │
1415       │                           │ compiler_check             
1416       │                           │ (CCACHE_COMPILERCHECK)     │
1417       │                           │ failed.                    │
1418       ├───────────────────────────┼────────────────────────────┤
1419       │                           │                            │
1420       │Compiler output file       │ One of the files expected  │
1421       │missing                    │ to be produced by the      │
1422       │                           │ compiler was missing after │
1423       │                           │ compilation.               │
1424       ├───────────────────────────┼────────────────────────────┤
1425       │                           │                            │
1426       │Compiler produced empty    │ The compiler’s output file │
1427       │output                     │ (typically an object file) │
1428       │                           │ was empty after            │
1429       │                           │ compilation.               │
1430       ├───────────────────────────┼────────────────────────────┤
1431       │                           │                            │
1432       │Could not find the         │ The compiler to execute    │
1433       │compiler                   │ could not be found.        │
1434       ├───────────────────────────┼────────────────────────────┤
1435       │                           │                            │
1436       │Error hashing extra file   │ Failure reading a file     │
1437       │                           │ specified by               │
1438       │                           │ extra_files_to_hash        
1439       │                           │ (CCACHE_EXTRAFILES).       │
1440       ├───────────────────────────┼────────────────────────────┤
1441       │                           │                            │
1442       │Forced recache             │ CCACHE_RECACHE was used to │
1443       │                           │ overwrite an existing      │
1444       │                           │ result.                    │
1445       ├───────────────────────────┼────────────────────────────┤
1446       │                           │                            │
1447       │Internal error             │ Unexpected failure, e.g.   │
1448       │                           │ due to problems            │
1449       │                           │ reading/writing the cache. │
1450       ├───────────────────────────┼────────────────────────────┤
1451       │                           │                            │
1452       │Missing cache file         │ A file was unexpectedly    │
1453       │                           │ missing from the cache.    │
1454       │                           │ This only happens in rare  │
1455       │                           │ situations, e.g. if one    │
1456       │                           │ ccache instance is about   │
1457       │                           │ to get a file from the     │
1458       │                           │ cache while another        │
1459       │                           │ instance removed the file  │
1460       │                           │ as part of cache cleanup.  │
1461       ├───────────────────────────┼────────────────────────────┤
1462       │                           │                            │
1463       │Multiple source files      │ The compiler was called to │
1464       │                           │ compile multiple source    │
1465       │                           │ files in one go. This is   │
1466       │                           │ not supported by ccache.   │
1467       ├───────────────────────────┼────────────────────────────┤
1468       │                           │                            │
1469       │No input file              │ No input file was          │
1470       │                           │ specified to the compiler. │
1471       ├───────────────────────────┼────────────────────────────┤
1472       │                           │                            │
1473       │Output to stdout           │ The compiler was           │
1474       │                           │ instructed to write its    │
1475       │                           │ output to standard output  │
1476       │                           │ using -o -. This is not    │
1477       │                           │ supported by ccache.       │
1478       ├───────────────────────────┼────────────────────────────┤
1479       │                           │                            │
1480       │Preprocessing failed       │ Preprocessing the source   │
1481       │                           │ code using the compiler’s  │
1482       │                           │ -E option failed.          │
1483       ├───────────────────────────┼────────────────────────────┤
1484       │                           │                            │
1485       │Unsupported code directive │ Code like the assembler    │
1486       │                           │ .incbin directive was      │
1487       │                           │ found. This is not         │
1488       │                           │ supported by ccache.       │
1489       ├───────────────────────────┼────────────────────────────┤
1490       │                           │                            │
1491       │Unsupported compiler       │ A compiler option not      │
1492       │option                     │ supported by ccache was    │
1493       │                           │ found.                     │
1494       ├───────────────────────────┼────────────────────────────┤
1495       │                           │                            │
1496       │Unsupported environment    │ An environment variable    │
1497       │variable                   │ not supported by ccache    │
1498       │                           │ was set.                   │
1499       ├───────────────────────────┼────────────────────────────┤
1500       │                           │                            │
1501       │Unsupported source         │ A source language e.g.     │
1502       │language                   │ specified with -x was      │
1503       │                           │ unsupported by ccache.     │
1504       └───────────────────────────┴────────────────────────────┘
1505

HOW CCACHE WORKS

1507       The basic idea is to detect when you are compiling exactly the same
1508       code a second time and reuse the previously produced output. The
1509       detection is done by hashing different kinds of information that should
1510       be unique for the compilation and then using the hash sum to identify
1511       the cached output. Ccache uses BLAKE3, a very fast cryptographic hash
1512       algorithm, for the hashing. On a cache hit, ccache is able to supply
1513       all of the correct compiler outputs (including all warnings, dependency
1514       file, etc) from the cache. Data stored in the cache is checksummed with
1515       XXH3, an extremely fast non-cryptographic algorithm, to detect
1516       corruption.
1517
1518       Ccache has two ways of gathering information used to look up results in
1519       the cache:
1520
1521       •   the preprocessor mode, where ccache runs the preprocessor on the
1522           source code and hashes the result
1523
1524       •   the direct mode, where ccache hashes the source code and include
1525           files directly
1526
1527       The direct mode is generally faster since running the preprocessor has
1528       some overhead.
1529
1530       If no previous result is detected (i.e., there is a cache miss) using
1531       the direct mode, ccache will fall back to the preprocessor mode unless
1532       the depend mode is enabled. In the depend mode, ccache never runs the
1533       preprocessor, not even on cache misses. Read more in The depend mode
1534       below.
1535
1536   Common hashed information
1537       The following information is always included in the hash:
1538
1539       •   the extension used by the compiler for a file with preprocessor
1540           output (normally .i for C code and .ii for C++ code)
1541
1542       •   the compiler’s size and modification time (or other
1543           compiler-specific information specified by compiler_check)
1544
1545       •   the name of the compiler
1546
1547       •   the current directory (if hash_dir is enabled)
1548
1549       •   contents of files specified by extra_files_to_hash (if any)
1550
1551   The preprocessor mode
1552       In the preprocessor mode, the hash is formed of the common information
1553       and:
1554
1555       •   the preprocessor output from running the compiler with -E
1556
1557       •   the command line options except those that affect include files
1558           (-I, -include, -D, etc; the theory is that these command line
1559           options will change the preprocessor output if they have any effect
1560           at all)
1561
1562       •   any standard error output generated by the preprocessor
1563
1564       Based on the hash, the cached compilation result can be looked up
1565       directly in the cache.
1566
1567   The direct mode
1568       In the direct mode, the hash is formed of the common information and:
1569
1570       •   the input source file
1571
1572       •   the compiler options
1573
1574       Based on the hash, a data structure called “manifest” is looked up in
1575       the cache. The manifest contains:
1576
1577       •   references to cached compilation results (object file, dependency
1578           file, etc) that were produced by previous compilations that matched
1579           the hash
1580
1581       •   paths to the include files that were read at the time the
1582           compilation results were stored in the cache
1583
1584       •   hash sums of the include files at the time the compilation results
1585           were stored in the cache
1586
1587       The current contents of the include files are then hashed and compared
1588       to the information in the manifest. If there is a match, ccache knows
1589       the result of the compilation. If there is no match, ccache falls back
1590       to running the preprocessor. The output from the preprocessor is parsed
1591       to find the include files that were read. The paths and hash sums of
1592       those include files are then stored in the manifest along with
1593       information about the produced compilation result.
1594
1595       There is a catch with the direct mode: header files that were used by
1596       the compiler are recorded, but header files that were not used, but
1597       would have been used if they existed, are not. So, when ccache checks
1598       if a result can be taken from the cache, it currently can’t check if
1599       the existence of a new header file should invalidate the result. In
1600       practice, the direct mode is safe to use in the absolute majority of
1601       cases.
1602
1603       The direct mode will be disabled if any of the following holds:
1604
1605direct_mode is false
1606
1607       •   a modification time of one of the include files is too new (needed
1608           to avoid a race condition)
1609
1610       •   a compiler option not supported by the direct mode is used:
1611
1612           •   a -Wp,* compiler option other than -Wp,-MD,<path>,
1613               -Wp,-MMD,<path>, -Wp,-D<macro[=defn]> or -Wp,-U<macro>
1614
1615-Xpreprocessor
1616
1617       •   the string __TIME__ is present in the source code
1618
1619   The depend mode
1620       If the depend mode is enabled, ccache will not use the preprocessor at
1621       all. The hash used to identify results in the cache will be based on
1622       the direct mode hash described above plus information about include
1623       files read from the dependency list generated by MSVC with
1624       /showIncludes, or the dependency file generated by other compilers with
1625       -MD or -MMD.
1626
1627       Advantages:
1628
1629       •   The ccache overhead of a cache miss will be much smaller.
1630
1631       •   Not running the preprocessor at all can be good if compilation is
1632           performed remotely, for instance when using distcc or similar;
1633           ccache then won’t make potentially costly preprocessor calls on the
1634           local machine.
1635
1636       Disadvantages:
1637
1638       •   The cache hit rate will likely be lower since any change to
1639           compiler options or source code will make the hash different.
1640           Compare this with the default setup where ccache will fall back to
1641           the preprocessor mode, which is tolerant to some types of changes
1642           of compiler options and source code changes.
1643
1644       •   If -MD is used, the manifest entries will include system header
1645           files as well, thus slowing down cache hits slightly, just as using
1646           -MD slows down make. This is also the case for MSVC with
1647           /showIncludes.
1648
1649       •   If -MMD is used, the manifest entries will not include system
1650           header files, which means ccache will ignore changes in them.
1651
1652       The depend mode will be disabled if any of the following holds:
1653
1654depend_mode is false.
1655
1656run_second_cpp is false.
1657
1658       •   The compiler is not generating dependencies using -MD or -MMD (for
1659           MSVC, /showIncludes is added automatically if not specified by the
1660           user).
1661

HANDLING OF NEWLY CREATED HEADER FILES

1663       If modification time (mtime) or status change time (ctime) of one of
1664       the include files is equal to (or newer than) the time compilation is
1665       being done, ccache disables the direct mode (or, in the case of a
1666       precompiled header, disables caching completely). This done as a safety
1667       measure to avoid a race condition (see below).
1668
1669       To be able to use a newly created header files in direct mode (or use a
1670       newly precompiled header), either:
1671
1672       •   create the include file earlier in the build process, or
1673
1674       •   set sloppiness to include_file_ctime,include_file_mtime if you are
1675           willing to take the risk, for instance if you know that your build
1676           system is robust enough not to trigger the race condition.
1677
1678       For reference, the race condition mentioned above consists of these
1679       events:
1680
1681        1. The preprocessor is run.
1682
1683        2. An include file is modified by someone.
1684
1685        3. The new include file is hashed by ccache.
1686
1687        4. The real compiler is run on the preprocessor’s output, which
1688           contains data from the old header file.
1689
1690        5. The wrong object file is stored in the cache.
1691

CACHE DEBUGGING

1693       To find out what information ccache actually is hashing, you can enable
1694       the debug mode via the configuration option debug or by setting
1695       CCACHE_DEBUG in the environment. This can be useful if you are
1696       investigating why you don’t get cache hits. Note that performance will
1697       be reduced slightly.
1698
1699       When the debug mode is enabled, ccache will create up to five
1700       additional files next to the object file:
1701
1702       ┌───────────────────────────────────────────┬───────────────────────────┐
1703       │                                           │                           │
1704Filename                                   Description               
1705       ├───────────────────────────────────────────┼───────────────────────────┤
1706       │                                           │                           │
1707<objectfile>.<timestamp>.ccache-input-c    │ Binary input hashed by    │
1708       │                                           │ both the direct mode and  │
1709       │                                           │ the preprocessor mode.    │
1710       ├───────────────────────────────────────────┼───────────────────────────┤
1711       │                                           │                           │
1712<objectfile>.<timestamp>.ccache-input-d    │ Binary input only hashed  │
1713       │                                           │ by the direct mode.       │
1714       ├───────────────────────────────────────────┼───────────────────────────┤
1715       │                                           │                           │
1716<objectfile>.<timestamp>.ccache-input-p    │ Binary input only hashed  │
1717       │                                           │ by the preprocessor mode. │
1718       ├───────────────────────────────────────────┼───────────────────────────┤
1719       │                                           │                           │
1720<objectfile>.<timestamp>.ccache-input-text │ Human-readable combined   │
1721       │                                           │ diffable text version of  │
1722       │                                           │ the three files above.    │
1723       ├───────────────────────────────────────────┼───────────────────────────┤
1724       │                                           │                           │
1725<objectfile>.<timestamp>.ccache-log        │ Log for this object file. │
1726       └───────────────────────────────────────────┴───────────────────────────┘
1727
1728            The timestamp format is
1729           `<year><month><day>_<hour><minute><second>_<microsecond>`.
1730
1731       If debug_dir (environment variable CCACHE_DEBUGDIR) is set, the files
1732       above will be written to that directory with full absolute paths
1733       instead of next to the object file.
1734
1735       In the direct mode, ccache uses the 160 bit BLAKE3 hash of the
1736       “ccache-input-c” + “ccache-input-d” data (where + means concatenation),
1737       while the “ccache-input-c” + “ccache-input-p” data is used in the
1738       preprocessor mode.
1739
1740       The “ccache-input-text” file is a combined text version of the three
1741       binary input files. It has three sections (“COMMON”, “DIRECT MODE” and
1742       “PREPROCESSOR MODE”), which is turn contain annotations that say what
1743       kind of data comes next.
1744
1745       To debug why you don’t get an expected cache hit for an object file,
1746       you can do something like this:
1747
1748        1. Enable debug (CCACHE_DEBUG).
1749
1750        2. Build.
1751
1752        3. Clean and build again.
1753
1754        4. Compare the <objectfile>.<timestamp>.ccache-input-text files for
1755           the two builds. This together with the
1756           <objectfile>.<timestamp>.ccache-log files should give you some
1757           clues about what is happening.
1758

COMPILING IN DIFFERENT DIRECTORIES

1760       Some information included in the hash that identifies a unique
1761       compilation can contain absolute paths:
1762
1763       •   The preprocessed source code may contain absolute paths to include
1764           files if the compiler option -g is used or if absolute paths are
1765           given to -I and similar compiler options.
1766
1767       •   Paths specified by compiler options (such as -I, -MF, etc) on the
1768           command line may be absolute.
1769
1770       •   The source code file path may be absolute, and that path may
1771           substituted for __FILE__ macros in the source code or included in
1772           warnings emitted to standard error by the preprocessor.
1773
1774       This means that if you compile the same code in different locations,
1775       you can’t share compilation results between the different build
1776       directories since you get cache misses because of the absolute build
1777       directory paths that are part of the hash.
1778
1779       Here’s what can be done to enable cache hits between different build
1780       directories:
1781
1782       •   If you build with -g (or similar) to add debug information to the
1783           object file, you must either:
1784
1785           •   use the compiler option -fdebug-prefix-map=<old>=<new> for
1786               relocating debug info to a common prefix (e.g.
1787               -fdebug-prefix-map=$PWD=.); or
1788
1789           •   set hash_dir = false.
1790
1791       •   If you use absolute paths anywhere on the command line (e.g. the
1792           source code file path or an argument to compiler options like -I
1793           and -MF), you must set base_dir to an absolute path to a “base
1794           directory”. Ccache will then rewrite absolute paths under that
1795           directory to relative before computing the hash.
1796

PRECOMPILED HEADERS

1798       Ccache has support for precompiled headers with GCC and Clang. However,
1799       you have to do some things to make it work properly:
1800
1801       •   You must set sloppiness to pch_defines,time_macros. The reason is
1802           that ccache can’t tell whether __TIME__, __DATE__ or __TIMESTAMP__
1803           is used when using a precompiled header. Further, it can’t detect
1804           changes in #defines in the source code because of how preprocessing
1805           works in combination with precompiled headers.
1806
1807       •   You may also want to include include_file_mtime,include_file_ctime
1808           in sloppiness. See HANDLING OF NEWLY CREATED HEADER FILES.
1809
1810       •   You must either:
1811
1812           •   use the compiler option -include to include the precompiled
1813               header (i.e., don’t use #include in the source code to include
1814               the header; the filename itself must be sufficient to find the
1815               header, i.e. -I paths are not searched); or
1816
1817           •   (for the Clang compiler) use the compiler option -include-pch
1818               to include the PCH file generated from the precompiled header;
1819               or
1820
1821           •   (for the GCC compiler) add the compiler option -fpch-preprocess
1822               when compiling.
1823
1824       •   If you use Clang, you must compile with -fno-pch-timestamp.
1825
1826       If you don’t do this, either the non-precompiled version of the header
1827       file will be used (if available) or ccache will fall back to running
1828       the real compiler and increase the statistics counter “Preprocessing
1829       failed” (if the non-precompiled header file is not available).
1830

C++ MODULES

1832       Ccache has support for Clang’s -fmodules option. In practice ccache
1833       only additionally hashes module.modulemap files; it does not know how
1834       Clang handles its cached binary form of modules so those are ignored.
1835       This should not matter in practice: as long as everything else
1836       (including module.modulemap files) is the same the cached result should
1837       work. Still, you must set sloppiness to modules to allow caching.
1838
1839       You must use both direct mode and depend mode. When using the
1840       preprocessor mode Clang does not provide enough information to allow
1841       hashing of module.modulemap files.
1842

SHARING A LOCAL CACHE

1844       A group of developers can increase the cache hit rate by sharing a
1845       local cache directory. To share a local cache without unpleasant side
1846       effects, the following conditions should to be met:
1847
1848       •   Use the same cache directory.
1849
1850       •   Make sure that the configuration option hard_link is false (which
1851           is the default).
1852
1853       •   Make sure that all users are in the same group.
1854
1855       •   Set the configuration option umask to 002. This ensures that cached
1856           files are accessible to everyone in the group.
1857
1858       •   Make sure that all users have write permission in the entire cache
1859           directory (and that you trust all users of the shared cache).
1860
1861       •   Make sure that the setgid bit is set on all directories in the
1862           cache. This tells the filesystem to inherit group ownership for new
1863           directories. The following command might be useful for this:
1864
1865               find $CCACHE_DIR -type d | xargs chmod g+s
1866
1867       The reason to avoid the hard link mode is that the hard links cause
1868       unwanted side effects, as all links to a cached file share the file’s
1869       modification timestamp. This results in false dependencies to be
1870       triggered by timestamp-based build systems whenever another user links
1871       to an existing file. Typically, users will see that their libraries and
1872       binaries are relinked without reason.
1873
1874       You may also want to make sure that a base directory is set
1875       appropriately, as discussed in a previous section.
1876

SHARING A CACHE ON NFS

1878       It is possible to put the cache directory on an NFS filesystem (or
1879       similar filesystems), but keep in mind that:
1880
1881       •   Having the cache on NFS may slow down compilation. Make sure to do
1882           some benchmarking to see if it’s worth it.
1883
1884       •   Ccache hasn’t been tested very thoroughly on NFS.
1885
1886       A tip is to set temporary_dir to a directory on the local host to avoid
1887       NFS traffic for temporary files.
1888
1889       It is recommended to use the same operating system version when using a
1890       shared cache. If operating system versions are different then system
1891       include files will likely be different and there will be few or no
1892       cache hits between the systems. One way of improving cache hit rate in
1893       that case is to set sloppiness to system_headers to ignore system
1894       headers.
1895
1896       An alternative to putting the main cache directory on NFS is to set up
1897       a remote storage file cache.
1898

USING CCACHE WITH OTHER COMPILER WRAPPERS

1900       The recommended way of combining ccache with another compiler wrapper
1901       (such as “distcc”) is by letting ccache execute the compiler wrapper.
1902       This is accomplished by defining prefix_command, for example by setting
1903       the environment variable CCACHE_PREFIX to the name of the wrapper (e.g.
1904       distcc). Ccache will then prefix the command line with the specified
1905       command when running the compiler. To specify several prefix commands,
1906       set prefix_command to a colon-separated list of commands.
1907
1908       Unless you set compiler_check to a suitable command (see the
1909       description of that configuration option), it is not recommended to use
1910       the form ccache anotherwrapper compiler args as the compilation
1911       command. It’s also not recommended to use the masquerading technique
1912       for the other compiler wrapper. The reason is that by default, ccache
1913       will in both cases hash the mtime and size of the other wrapper instead
1914       of the real compiler, which means that:
1915
1916       •   Compiler upgrades will not be detected properly.
1917
1918       •   The cached results will not be shared between compilations with and
1919           without the other wrapper.
1920
1921       Another minor thing is that if prefix_command is used, ccache will not
1922       invoke the other wrapper when running the preprocessor, which increases
1923       performance. You can use prefix_command_cpp if you also want to invoke
1924       the other wrapper when doing preprocessing (normally by adding -E).
1925

CAVEATS

1927       •   The direct mode fails to pick up new header files in some rare
1928           scenarios. See The direct mode above.
1929

TROUBLESHOOTING

1931   General
1932       A general tip for getting information about what ccache is doing is to
1933       enable debug logging by setting the configuration option debug (or the
1934       environment variable CCACHE_DEBUG); see CACHE DEBUGGING for more
1935       information. Another way of keeping track of what is happening is to
1936       check the output of ccache -s.
1937
1938   Performance
1939       Ccache has been written to perform well out of the box, but sometimes
1940       you may have to do some adjustments of how you use the compiler and
1941       ccache in order to improve performance.
1942
1943       Since ccache works best when I/O is fast, put the cache directory on a
1944       fast storage device if possible. Having lots of free memory so that
1945       files in the cache directory stay in the disk cache is also preferable.
1946
1947       A good way of monitoring how well ccache works is to run ccache -s
1948       before and after your build and then compare the statistics counters.
1949       Here are some common problems and what may be done to increase the hit
1950       rate:
1951
1952       •   If the counter for preprocessed cache hits has been incremented
1953           instead of the one for direct cache hits, ccache has fallen back to
1954           preprocessor mode, which is generally slower. Some possible reasons
1955           are:
1956
1957           •   The source code has been modified in such a way that the
1958               preprocessor output is not affected.
1959
1960           •   Compiler arguments that are hashed in the direct mode but not
1961               in the preprocessor mode have changed (-I, -include, -D, etc)
1962               and they didn’t affect the preprocessor output.
1963
1964           •   The compiler option -Xpreprocessor or -Wp,* (except
1965               -Wp,-MD,<path>, -Wp,-MMD,<path>, and -Wp,-D<define>) is used.
1966
1967           •   This was the first compilation with a new value of the base
1968               directory.
1969
1970           •   A modification or status change time of one of the include
1971               files is too new (created the same second as the compilation is
1972               being done). See HANDLING OF NEWLY CREATED HEADER FILES.
1973
1974           •   The __TIME__ preprocessor macro is (potentially) being used.
1975               Ccache turns off direct mode if __TIME__ is present in the
1976               source code. This is done as a safety measure since the string
1977               indicates that a __TIME__ macro may affect the output. (To be
1978               sure, ccache would have to run the preprocessor, but the sole
1979               point of the direct mode is to avoid that.) If you know that
1980               __TIME__ isn’t used in practise, or don’t care if ccache
1981               produces objects where __TIME__ is expanded to something in the
1982               past, you can set sloppiness to time_macros.
1983
1984           •   The __DATE__ preprocessor macro is (potentially) being used and
1985               the date has changed. This is similar to how __TIME__ is
1986               handled. If __DATE__ is present in the source code, ccache
1987               hashes the current date in order to be able to produce the
1988               correct object file if the __DATE__ macro affects the output.
1989               If you know that __DATE__ isn’t used in practise, or don’t care
1990               if ccache produces objects where __DATE__ is expanded to
1991               something in the past, you can set sloppiness to time_macros.
1992
1993           •   The __TIMESTAMP__ preprocessor macro is (potentially) being
1994               used and the source file’s modification time has changed. This
1995               is similar to how __TIME__ is handled. If __TIMESTAMP__ is
1996               present in the source code, ccache hashes the string
1997               representation of the source file’s modification time in order
1998               to be able to produce the correct object file if the
1999               __TIMESTAMP__ macro affects the output. If you know that
2000               __TIMESTAMP__ isn’t used in practise, or don’t care if ccache
2001               produces objects where __TIMESTAMP__ is expanded to something
2002               in the past, you can set sloppiness to time_macros.
2003
2004           •   The input file path has changed. Ccache includes the input file
2005               path in the direct mode hash to be able to take relative
2006               include files into account and to produce a correct object file
2007               if the source code includes a __FILE__ macro.
2008
2009       •   If a cache hit counter was not incremented even though the same
2010           code has been compiled and cached before, ccache has either
2011           detected that something has changed anyway or a cleanup has been
2012           performed (either explicitly or implicitly when a cache limit has
2013           been reached). Some perhaps unobvious things that may result in a
2014           cache miss are usage of __TIME__, __DATE__ or __TIMESTAMP__ macros,
2015           or use of automatically generated code that contains a timestamp,
2016           build counter or other volatile information.
2017
2018       •   If “Multiple source files” has been incremented, it’s an indication
2019           that the compiler has been invoked on several source code files at
2020           once. Ccache doesn’t support that. Compile the source code files
2021           separately if possible.
2022
2023       •   If “Unsupported compiler option” has been incremented, enable debug
2024           logging and check which compiler option was rejected.
2025
2026       •   If “Preprocessing failed” has been incremented, one possible reason
2027           is that precompiled headers are being used. See PRECOMPILED HEADERS
2028           for how to remedy this.
2029
2030       •   If “Could not use precompiled header” has been incremented, see
2031           PRECOMPILED HEADERS.
2032
2033       •   If “Could not use modules” has been incremented, see C++ MODULES.
2034
2035   Corrupt object files
2036       It should be noted that ccache is susceptible to general storage
2037       problems. If a bad object file sneaks into the cache for some reason,
2038       it will of course stay bad. Some possible reasons for erroneous object
2039       files are bad hardware (disk drive, disk controller, memory, etc),
2040       buggy drivers or file systems, a bad prefix_command or compiler
2041       wrapper. If this happens, the easiest way of fixing it is this:
2042
2043        1. Build so that the bad object file ends up in the build tree.
2044
2045        2. Remove the bad object file from the build tree.
2046
2047        3. Rebuild with CCACHE_RECACHE set.
2048
2049       An alternative is to clear the whole cache with ccache -C if you don’t
2050       mind losing other cached results.
2051
2052       There are no reported issues about ccache producing broken object files
2053       reproducibly. That doesn’t mean it can’t happen, so if you find a
2054       repeatable case, please report it.
2055

MORE INFORMATION

2057       Credits, mailing list information, bug reporting instructions, source
2058       code, etc, can be found on ccache’s web site: https://ccache.dev.
2059

AUTHOR

2061       Ccache was originally written by Andrew Tridgell and is currently
2062       developed and maintained by Joel Rosdahl. See AUTHORS.txt or
2063       AUTHORS.html and https://ccache.dev/credits.html for a list of
2064       contributors.
2065
2066
2067
2068Ccache 4.8.2                      2023-07-19                         CCACHE(1)
Impressum