3

ccache 在 GitLab CI 中的缓存命中率为零,即使源不更改并且缓存保持不变。

此外,每次构建运行时缓存的大小都会增加,这意味着它会一遍又一遍地重建。

4

1 回答 1

7

问题是 ccache 检查编译器是否相同的默认方式 - 通过其时间戳。由于每个 GitLab CI 实例运行一个全新的 Docker 容器,这个时间戳总是不同的,因此总是构建新的缓存。

要解决此问题,请设置CCACHE_COMPILERCHECKcontent而不是默认的mtime.

从 ccache 文档:

compiler_check (CCACHE_COMPILERCHECK)
By default, ccache includes the modification time (“mtime”) and size of the compiler in the hash to ensure that results retrieved from the cache are accurate. This setting can be used to select another strategy. Possible values are:
    content
        Hash the content of the compiler binary. This makes ccache very slightly slower compared to the mtime setting, but makes it cope better with compiler upgrades during a build bootstrapping process.
    mtime
        Hash the compiler’s mtime and size, which is fast. This is the default.
于 2018-12-06T20:46:27.933 回答