Does "clear cache and deploy" removes everything under /opt/build/cache/

It’s more a question than a support request.

I know that on Netlify Hugo’s cache is stored under /opt/build/cache/hugo_cache.

Will running the build with clear cache and deploy action clear this directory and effectively “bust” hugo’s cache?

Thanks a ton!

Hi Regis!

I don’t think we do anything special with Hugo’s cache - are you putting it there? Here’s our cache handling from the shell script that runs your build, and I see no mention of hugo:

Regardless, the answer to your question is that clear cache and deploy means that we start without a cache, so nothing would be there to start with.

Now, could hugo choose to stick something there? Yes, definitely, and I think we’d save it since I think we save that entire directory. But Hugo would have to work without the cache since it is not guaranteed available (and in fact won’t be e.g. on a new site, or on a new branch or PR on an existing site where we start with fresh cache).

Could you remove it after build? Also yes - hugo && rm -rf $NETLIFY_CACHE_DIR/* would probably work.

Not sure why you were asking (as the main caching we intend to do with hugo’s output is at the CDN edge), but if that didn’t answer your question let me know some more about what you’re trying to accomplish :slight_smile:

Hugo only let us configure maxAge on cache on “fetch” type. So I can set that every json file called using Hugo’s getJSON has a maxAge of 1h for example. This does not suit us well. We’d like to be able to simply bust the cache so client can fetch new information regardless of time.

So the clear cache button seems like it would do that.

Now, I don’t think I can create a webhook that would clear the cache when invoked can I? Did not find any way to do so, maybe a mysterious environment variable?

Ah. That “cache clearing” only impacts build environment. You’d need to set or change custom headers if you are trying to affect the browsing experience:

No the JSON is consumed by Hugo at build time and stored in cache so it does not need to call the API on subsequent builds (until maxAge is reached), this is not client.

@regisphilibert, if Netlify is storing anything in a cache between builds, then this option when triggering deploys will delete any cache and start fresh.

So, if Netlify is caching that file (which I don’t know - but if), then this option will clear that build cache.

Does this help? If there are other questions, please let us know.