How to clear cache on branch deploy?

Hey,

How do we clear the cache on branch deploys? It’s possible on the master branch but not on other branches.

Also is it possible to clear the cache without doing a deploy?

We’re constantly having to clear the cache as we have our a private package repo on npm. Whenever we push changes to our own packages the deploy never picks them up unless we clear the cache first. Is this supposed to happen?

Thanks

Giles

Hi @gilesbutler! Welcome to netlify community.

There are several options here.

  1. You could update the package version specifically in package.json; then we should automatically install the newest version.
  2. If npm install doesn’t fail, you could make your build command something like npm i mypackage && npm run build
  3. We’ve just started to beta test build plugins, which will allow you to create custom logic
  4. Finally, yes, you could remove cache after each build by running something like npm run build && rm -rf /path/to/cache

Let us know what you decide to do!

Hi @laura,

Thanks for getting back to me. We already update the package version automatically as we’re updating dependencies, unfortunately Netlify doesn’t install the latest version unless we clear the cache. Is this a bug on your end?

Number 4 might be a bit of a workaround for now, we could use an environment variable to run a script to remove the cache. What is the path to the Netlify cache though? I assume it’s the same as the local cache e.g /node_modules/.cache?

Thanks

@gilesbutler, Netlify stores certain files in /opt/build/cache and reloads them each build to prevent downloading files more than once if we have copies already.

Note, the build runs in /opt/build/repo by default. Below is a copy of the command ls -alh ../cache which was run during a build of one of my Netlify sites:

11:59:11 PM: drwxr-xr-x 18 buildbot root    4.0K Dec  2 07:58 .
11:59:11 PM: drwxr-xr-x  4 buildbot root    4.0K Dec  2 07:58 ..
11:59:11 PM: drwxr-xr-x  3 buildbot nogroup 4.0K Nov 22 20:20 .boot
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 bower_components
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 .bundle
11:59:11 PM: drwx------  3 buildbot nogroup 4.0K Nov 22 20:19 .cache
11:59:11 PM: drwxr-xr-x  9 buildbot nogroup 4.0K Nov 22 20:20 .cask
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 .composer
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 .emacs.d
11:59:11 PM: drwxr-xr-x  3 buildbot nogroup 4.0K Oct 30 06:41 hugo_cache
11:59:11 PM: drwxr-xr-x  3 buildbot nogroup 4.0K Nov 22 20:20 .m2
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 node_modules
11:59:11 PM: drwxr-xr-x  4 buildbot nogroup 4.0K Oct 30 06:41 node_version
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Dec  2 07:58 ruby_version
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 .venv
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 wapm_packages
11:59:11 PM: drwxr-xr-x  3 buildbot nogroup 4.0K Oct 30 06:41 .wasmer
11:59:11 PM: drwxr-xr-x  2 buildbot nogroup 4.0K Oct 30 06:41 .yarn_cache

Hopefully, this gives an overview of where to find the Netlify build cache and the types of files/directories which are stored there. To summarize, this cache located at ../cache relative to the base of the cloned repo (which is the default build directory).

​Please let us know if there are other questions about this.

Thanks for the follow up @luke.

Handy to know and that should come in useful :+1: