What is ccache? Can you provide some guidance on when to use it for building Bitcoin Core PRs and how to use it?
The tool ccache helps store intermediate compilation results, so if you changes branches often, and rebuild, it can significantly speed up doing so.
To use it, you install
ccache for your platform. That's it. The Bitcoin Core configure script will detect its presence, and use it automatically.
ccache is a compiler cache.
It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again.
Unlike dbcache the decision of how much ccache to allocate is not as critical. The Bitcoin Core productivity doc does recommend that you put something like this in
max_size = 50.0G # or whatever cache size you prefer; default is 5G; 0 means unlimited base_dir = /home/yourname # or wherever you keep your source files
Note: base_dir is required for ccache to share cached compiles of the same file across different repositories / paths; it will only do this for paths under base_dir. So this option is required for effective use of ccache with git worktrees.
You must not set base_dir to "/", or anywhere that contains system headers (according to the ccache docs).
There doesn't appear to be any obvious downsides to use
ccache. But there are a couple of warnings on the ccache site.
Compilers are moving targets. Newer compiler versions may, and often do, introduce features that ccache can't foresee.
The fastest mode (the "direct mode") has a corner case which can result in false positive cache hits.
Generally though it appears you can just install it (as Pieter says) and forget about it and this will save you time on compiling Bitcoin Core PRs.
For other information on speeding up C++ compilation see this excellent blog post from Martin Hořeňovský.