-
Can someone please help me understand how the cache keys work in the Cache Action? Here are the things I do not fully understand.
So, as I understand it, the cache key will change with every commit, and therefore, not be a “cache hit”. What reason is there to use the commit sha in the cache key?
The documentation on restore-keys states that there are “fallback keys” if no cache hit occurred. So does it mean that when caching is done, it will be cached using two keys, and the topmost key will be selected on restore? Or, is the “restore-keys” option actually listing prefixes of keys, so its meaning is more like “${{ runner.os }}-docker- *”? If the answer is the latter, then it explains the first question as well, at least to some extent. If these are not prefixes, then why is everybody using a trailing hyphen in the restore key names?
A quote from the restore key documentaiton:
But the syntax everywhere, is actually used like this:
which is not an ordered list, but rather a newline delimited string. I expected the syntax to match the definition (and actually be an oordered list), which makes more sense to me here:
What is the reason for this variable typed as a newline delimited string, instead of a proper YAML array? Sorry for the long post, hoping someone has the patience to elaborate, and if this is you - thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Caches not only can be shared between workflow runs, you also can share caches between jobs in the same workflow run. So when using github.sha in the key is feasible. The key can be any combination of variables, context values, static strings, and functions.
More details, you can reference the documentation about Caching dependencies to speed up workflows. |
Beta Was this translation helpful? Give feedback.
Caches not only can be shared between workflow runs, you also can share caches between jobs in the same workflow run. So when using github.sha in the key is feasible. The key can be any combination of variables, context values, static strings, and functions.
An ordered list of alternative keys to use for finding the cache if no cache hit occurred for key. If you provide restore-keys, the cache action sequentially searches for any caches that match the list of restore-keys.