How to disable the cdn for content?

I just had an issue where I changed the slug and it broke my page for a couple of hours.

The CDN for one record was returning the old slug, and the CDN for fetching the slug directly was serving the new content (404 for the old slug). I tried creating a new primary environment, unpublishing and republishing the document, but console.logging the response from the graphql endpoint was still returning the old slug

I actually don’t want to use the CDN at all, my nextjs caches everything for a couple of hours and I’d much rather have the real content than some cached content

Hi @manthan, and welcome to the community!

Can I ask, please, what exactly you mean by the “CDN was returning the old slug”? Can you please share the actual code or query you’re using so we can see what you mean?

Just a guess: Are you trying to query our Content Delivery GraphQL API from Next.js, but you’re seeing old data? Those API calls actually shouldn’t be cached by us.

Is it possible you’re seeing caching from the Next.js fetch cache? In newer versions of Next.js, they not only CDN everything, but override the vanilla JS fetch() command with a cache, making it seem like we’re returning stale data when it’s actually their cache that’s not invalidating.

You can disable that behavior by specifying the revalidate option with a number >=0 : Functions: fetch | Next.js

fetch('url', { next: { revalidate: 0 } }) will disable the cache altogether and always talk live to our API.

If that’s not what you mean, could you please provide some sample code and responses so we can see exactly what you’re trying to do?

Thank you!

(Just to be clear, our CDN caches should only be for media, like images and videos. Our APIs should never return stale data as long as you’re able to hit them directly. You can verify this with something like Postman, making the same calls as in your code, and seeing if you get back the same responses… if not, Next is caching something.)

Hey, thanks for the response. I’m aware of nextjs caching behavior but I was also experiencing this locally even after server restarts. It’s unclear to me if next.js retains the cache on disk or something like that. The next time something like this happens, I’ll make sure to test and circle back. Good to know that Dato doesn’t cache in front

It’s not super clear to me either. Their docs aren’t explicit about this, just saying:

“The Data Cache is persistent across incoming requests and deployments unless you revalidate or opt-out.”

That suggests to me there is some sort of disk caching going on (otherwise how would different deployments share the same cache? unless they have some sort of memory/environment sharing between them, which seems pretty strange).

EDIT: From another docs page:

“Next.js can cache responses, generated static pages, [etc., …].
[…]
By default, this cache is stored to the filesystem (on disk) on your Next.js server. This works automatically when self-hosting using both the Pages and App Router.”

It’s still not super-explicit whether this same disk cache also applies to the fetch() data cache, but it at least verifies that there are some on-disk caches.

One way to test it easily might be to temporarily delete/rename the .next folder in your repo before restarting?


Also, I should reiterate that this is only a theory :frowning: I’m suggesting this because it’s caught several of our customers off-guard. But if that doesn’t fix it, please let us know how exactly you’re querying the APIs (i.e. sample code) and we’ll help you investigate from there!