Maarten Bamelis
Maarten Bamelis

Reputation: 2423

Configure Ccache to only use secondary storage?

How can I configure Ccache to only use secondary storage as it's cache and completely skip primary storage?


Our CI pipelines use containers to compile and build our C++ application. We want to use Ccache to reduce build times and want the cache to be shared with all pipelines. For this, the secondary storage options of Ccache seem ideal but we don't know how we can configure Ccache to skip the primary storage (local cache) completely.

We would like Ccache to immediately contact the secondary storage but I think it would also be okay if the local cache generated cache misses first. Ideally, the local cache is not updated as to not waste time there. Of course, it's a must-have that the secondary storage is updated whenever a miss occurs.

I was thinking of setting --max-files or --max-size to 0 but that is a special value to set no limit at all. Setting those options to 1 would maybe work but it will also needlessly trigger the cleanup logic of Ccache, wasting time.

I also noticed the configuration option read_only but the documentation clearly states: "... but it will not add new results to any cache backend", which means our secondary storage would never be updated.

Upvotes: 1

Views: 847

Answers (3)

Joel Rosdahl
Joel Rosdahl

Reputation: 904

You can configure Ccache version 4.7 and newer to use only remote storage (used to be called secondary storage) by setting remote_only = true in the configuration file, or set the environment variable CCACHE_REMOTE_ONLY.

Documentation of the feature: https://ccache.dev/manual/4.7.4.html#config_remote_only

Upvotes: 2

Jorge Bellon
Jorge Bellon

Reputation: 3106

Have you considered using any alternatives? sccache supports sharing a single cache across builders, so it may be exactly what you are looking for.

Upvotes: 1

Sree Gowtham Josyula
Sree Gowtham Josyula

Reputation: 58

In following function of ccache repository - https://github.com/ccache/ccache/blob/3a2f970842417ea605d24b07af652be91c7eff31/src/storage/Storage.cpp#L292, it seems to me that it is not possible to put a file in secondary storage immediately without first updating the primary storage. In my understanding, your best bet would be to configure --max-size to a reasonably small value as your have mentioned.

Upvotes: 1

Related Questions