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
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?
(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
â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).
â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 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!