Force Refresh of TTL for On-Demand-Builders

Hi everyone

I have the following task:

We have a CMS which content is being fetched by nuxt/gql. Instead of generating statically on netlify we now use On-Demand Builders. As I understand all the pages are being regenerated indepenent of caching, because the content might have changed.

Instead we could increase the TTL values for on-demand builders.

What I would like to achieve is to set a high TTL for all pages but when somebody in the CMS saves a specific entry, I want to reset the TTL for that one specific page. Thereby saving lots of unnecessary “builds”, both saving energy and server ressources and also keeping our function metrics low.

So my first question: Did I understand correctly and would my plan be somehow possible?

Further I read this:

I have no idea how to build a custom builder. Or is this really just a URL? In the end I just want to invalidate some cached content (or reset TTL, how things are called on netlify).

I also read about durable directives. Is this maybe what I need?

If this is what I need, could somebody give me some pointers what has to be done?
As far as I understand

I need to set a serverless function in the durable directive. (I hope to find some online tutorial how to do that, if you have good resources I would be very glad to know)

But what do I do from there on?
How would I force a page to have all its cache reset but normally don’t invoke an on-demand builder?

I would be very glad to gain some insights here.
Thank you in advance.

Cheers

I won’t recommend using On Demand Builders at the moment. We released them back in the days to support Next.js ISR, but it has since been replaced with Cache-control headers and Durable Cache. It will continue to work, but cache-control headers should give you more control.

With that being said, manually purging On Demand Builders on demand has been a private beta feature. I don’t expect it will ever see the light of the day as cache-control headers already provide that functionality.

To achieve what you need:

  • set cache-control to public, max-age=0, must-revalidate
  • set netlify-cdn-cache-control to some high TTL value along with durable directive
  • set netlify-cache-tag header to some custom tag that you would like to purge in the future
  • purge the cache for the cache tag by following the documentation: Caching | Netlify Docs