Fix multiple caches hash collision
What does this MR do and why?
When using multiple caches for a single project, it may lead to a cache collision due to how we are calculating the key. There is currently a workaround by using the prefix
keyword, but we would like to fix this issue so that no workaround is necessary. This will only add a prefix if no prefix
is specified.
Screenshots or screen recordings
Before | After |
---|---|
With cache:key:prefix
, it does not add an index:
How to set up and validate locally
- Create a
.gitlab-ci.yaml
that has multiple cache keys that depend on the lock file. - Run the pipeline
- See cache key collision:
Creating cache 25b4b97e42e1c8264602627bd9591c7428c46135-1-non_protected...
node_modules/: found 844 matching files and directories
Creating cache 25b4b97e42e1c8264602627bd9591c7428c46135-1-non_protected...
folder2/node_modules/: found 2946 matching files and directories
Example Project
- Example Project: https://gitlab.com/gitlab-gold/faleksic-tests/public-group/ci-testing/-/tree/cache-collision
- Example Pipeline: https://gitlab.com/gitlab-gold/faleksic-tests/public-group/ci-testing/-/jobs/2461580650
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related: #362492 (closed)
Edited by Laura Montemayor