NextJS + Vercel + Dato Cache Tags not always working

I recently swapped a client project over to use the new cache tags – following the setup in this repo:

But it doesn’t always work, (notably when updates are being made to existing content) e.g.

  • My client makes an update to a blog post, publishes and on occasion it doesn’t update, but then if I go in make a content change and publish it shows the updated content
  • Client updates a “featured” article content type, publishes and on occasion, it doesn’t update
  • Client publishes a new article but the listing on the homepage doesn’t always update to show the new blog in the list

I’ve ended up creating a webhook that hits this endpoint to clear all the cache nextjs-with-cache-tags-starter/app/api/invalidate-all/route.ts at main · datocms/nextjs-with-cache-tags-starter · GitHub

But he’s having to use it far too often.

In this post (Introducing DatoCMS Cache Tags: Effortless, surgical page regeneration on content change) it says:

“consistently achieving a cache hit-ratio of over 90%”

Is that what we’re seeing here? Is it that the cache tags can sometimes miss a content type that’s updated?

I guess the first question is; is what we’re seeing expected behaviour and a limitation with the cache tags or have I missed something?

Hi @robsimpson, and welcome to the Dato forum!

Sorry that your post was accidentally flagged by the spam bot at first. (It said you typed too quickly – probably copied & pasted? I’ve disabled that rule to be safe.)

Anyway, if I’m understanding you right, the cache tags work fine as long as you’re the one doing the edits, but not if your client does the same edits? i.e. it doesn’t matter what model they’re working on, or what kind of edits they make, etc… as long as you go in after them into the same record to make some minor tweak (like adding/removing a space or whatever), THEN the cache tags work?

Hmm :thinking: I wonder if it might be some sort of roles/permissions/API key type thing, where their Dato user isn’t triggering the same invalidation workflow as your user would…?

Could you please send us the actual project URL (either in a reply post, or in a DM to me, or via email at support@datocms.com – whichever you prefer) so we can take a look at the specific setup and webhook activities log in there?

Edit: Also, can we please see the source code of your invalidate tags webhooks receiver? Not the “invalidate everything” one, but the one that’s supposed to invalidate just the affected tags.

Thank you!

And just to address this part of it:

It’s definitely not supposed to! A cache-hit ratio of over 90% means that the caching is working well (when it’s working right). But that should NOT mean that invalidations are difficult. The whole point of the cache tags is to make the invalidations simpler :slight_smile:

Definitely not! It’s supposed to work the way you envisioned (i.e., either of you make an edit, webhook gets fired, published page updates a few seconds later). If it’s not doing that, it’s either a bug on our part or perhaps a subtle issue in the implementation somewhere? Once you send us the project URL we can take a look together :slight_smile: