What is the cache ID for a job generated from? How can staged jobs use the same cache?

caching
docs

#1

Currently https://docs.travis-ci.com/user/caching#fetching-and-storing-caches says:

There is one cache per branch and language version / compiler version / JDK version / Gemfile location, etc.

This is too vague as it doesn’t give any way to determine if two jobs will be using the same or a different cache.

hxxps://github.com/travis-ci/travis-build/blob/master/lib/travis/build/script/shared/directory_cache/base.rb#L236-L253 and hxxps://github.com/travis-ci/travis-build/blob/master/lib/travis/build/script.rb#L147-L157 suggest that:

In the cache path, which looks like master/cache-osx-xcode8-88897247c8594340a4240d868adfe866078e00d71e4ad6a77ca222c2d9970d84.tgz,

the long hash is the hash of all environment variables specified in the .yml (they can be seen at the start of a build log) except the secret ones.

So,

  • The only way to reuse another job’s cache is to use the same exact system image and environment variables

Is all this right?

Does this mean that I cannot make a “shared” cache for multiple jobs? In particular, I’m looking into making a source distribution, then building it on all supported platforms.


#2

Further down in the document, there is a more comprehensive explanation of how cache names are determined. I will not repeat what’s written there.


Does this mean that I cannot make a “shared” cache for multiple jobs?

That is correct. If two jobs differ in any of the factors mentioned, they do not share the cache. The reason here is that, when multiple jobs share the same cache name, the cache can corrupt due to simultaneous access and it can cause a lot of problems.




all aim to address this issue to varying degrees. We have ideas about how to strike a balance (useful caching strategy while keeping the likelihood of cache corruption to a minimum), but the implementation would still need to be discussed and the actual work prioritized.


Allow a next-stage job read-only access to the cache of a previous-stage one; or make exported/imported artifacts
How can I share coverage information between build stages in PRs from forks?
#3

Thanks! I trusted the info to be complete because this is reference documentation.
Would you mind adding a reference?