Skip to content

Fix multiple caches hash collision

Laura Montemayor requested to merge fix-multiple-caches-hash-collision into master

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
Screenshot_2022-11-24_at_13.54.45 Screenshot_2022-11-24_at_13.40.37

With cache:key:prefix, it does not add an index: Screenshot_2022-11-24_at_13.54.06

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

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related: #362492 (closed)

Edited by Laura Montemayor

Merge request reports