I want to save a little bit of build time buy caching the node_modules of several subfolders in my project . Is this the right format.
```
image: node:18
clone: depth: full definitions:
caches:
node-modules-cache:
key: files: - "**/*"
path: src/sub-projects/**/node_modules/
steps: - step: &build-test name: Build and test caches: - node - node-modules-cache
```
Hi @simon,
I'm afraid that wildcards in a cache's path will not work. If you use a definition like this, a directory named ** will be created inside the src/sub-projects directory and then a directory named node_modules will be created inside the ** directory. So, that cache will not be used since it will not preserve the directory structure.
The workaround is to use a separate cache definition for each directory inside src/sub-projects, e.g:
definitions:
caches:
build-cache:
key:
files:
- package.json
path: src/sub-projects/componentA/node_modules
build-cache2:
key:
files:
- package.json
path: src/sub-projects/componentB/node_modules
We have a feature request for preserving the directory structure when wildcards are present in the cache path:
You can add your vote to that feature request (by selecting the link Vote for this issue) to increase the chances of this being implemented. You are more than welcome to leave feedback, and you can also add yourself as a watcher (by selecting the link Start watching this issue) if you'd like to be notified via email on updates.
You may also want to use specific files in the key files definition, like in my example above. With the pattern you currently have, "**/*", Pipelines is going to generate a new cache every time you push a change to any file at the root of your repo or its subdirectories and then the previously generated cache will not be used.
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.