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:

Hi all, I got here from Cache issue on Netlify? looking to find the answer to “how to purge cache when deploying via CLI”.

The problem is as stated in Cache issue on Netlify? that everything seems to be working fine, except for the live url, where the old version of the page is still deployed.

Since I deploy using CLI (no Github - Netlify integration), I also can’t "clear cache and deploy).

I read the thread above and I see some hints towards a “.cache” directory in the root folder, where netlify commands are run. However, I don’t have such a directory (I made sure to use “ls -alh” to see hidden files and folders). I have a .cache directory in node_modules, but nothing in connection with netlify deploys.

How can I purge cache before deploying to production, and isn’t this simply a bug when after deploying to production everything’s fine on the preview url, everything’s fine on the unique deploy url but the old version is on the live url? Seems like a bug to me…

1 Like

The problem “solved itself”. The cache must have been invalidated now in the meantime. That means, this issue is no longer reproducible for now. If someone would still like to investigate, I can make another change…

Hi, @glorifiedmonkey, the build cache and the cache for the CDN nodes are two different things.

It sounds like the issue you saw was with out of date content on the CDN, not in the build system. I just want to be clear which cache you are referring to and this topic is about a cache you aren’t using (as far as I can tell).

To keep things clear, I’ll no longer reply to this topic and follow-up in the first topic where this was commented about here.

1 Like