Home
Support Forums

Netlify cache util not working as expected

Hi, I am trying to cache files in between builds but with no success. I am trying to cache ./dist folder and its contents, that is - static and my-project-name folders (I am using Angular with Scully).

module.exports = {
  async onPreBuild({utils}) {
    await utils.cache.restore('./dist');
  },
  async onPostBuild({utils}) {
    await utils.cache.save('./dist');
  },
};

I did tens of console.logs, directory is correct, paths seem ok, files to cache are there, but when it caches it only shows ./dist/static/sitemap.xml as the only cached file. Interestingly, I no longer use sitemap plugin and it still shows that one file out of nowhere. I did clear Netlify cache, and still, same behaviour.

I also tried netlify-plugin-cache but behaviour is exactly the same. One happy thing is that locally with Netlify CLI (ntl build) it does work with zero issues, everything caches properly. Am I missing something? Thanks!

Hi, @AverageNetlifyBoi. One thing that jumps out is that you are saving before the build and then restoring after the build. Shouldn’t it be the other way around? Meaning, shouldn’t you restore before building and then save after the build is complete?

Sorry, I made a mistake writing this, post fixed (I do have correct implementation in my project).

Hi, @AverageNetlifyBoi. Many static site generators (SSGs) delete the contents of the “publish directory” (whatever that is for that particular SSG). I believe for Scully that is ./dist.

Are you sure it isn’t Scully itself deleting the contents of that directory?

I did console logs of all existing files and everything seems okay. Important thing to notice is that locally Netlify Dev does cache properly with zero problems. Issue only occurs during deployments.

Happy to check is. Is there a repo we could try?