How to disable cache in Sanity when useCdn is false but changes not reflected?
Good news - you've correctly set useCdn: false, which disables Sanity's CDN. However, the caching issue you're experiencing is almost certainly happening on the Next.js side, not Sanity's side.
Next.js has its own aggressive caching system that caches fetch requests by default. Even with useCdn: false, Next.js will still cache the responses from Sanity's API. Here's how to fix it:
Solution 1: Disable Next.js Cache with cache: 'no-store'
When fetching data, add the cache: 'no-store' option:
const data = await client.fetch(query, params, {
cache: 'no-store' // This disables Next.js caching
})Or if you're using the @sanity/client directly:
const data = await client.fetch(query, params, {
next: { revalidate: 0 } // Revalidate on every request
})Solution 2: Use Tag-Based Revalidation (Better for Production)
For a production-ready solution, use Next.js's tag-based revalidation. This lets you keep caching benefits while invalidating specific content when it changes:
// In your fetch
const data = await client.fetch(query, params, {
next: { tags: ['post', 'author'] }
})
// Create an API route at /app/api/revalidate/route.ts
import { revalidateTag } from 'next/cache'
import { type NextRequest, NextResponse } from 'next/server'
export async function POST(req: NextRequest) {
const { tags } = await req.json()
tags.forEach((tag: string) => revalidateTag(tag))
return NextResponse.json({ revalidated: true })
}Then set up a webhook in Sanity to call this endpoint when content changes.
Solution 3: Use Live Content API (Modern Approach)
If you're on a recent version of next-sanity, consider using the Live Content API which automatically handles caching and invalidation for you - no manual cache management needed.
Quick Debug Check
In development mode, try adding this to your next.config.js to see cache behavior more clearly:
module.exports = {
logging: {
fetches: {
fullUrl: true,
},
},
}The useCdn: false setting you've configured is correct for avoiding Sanity's CDN, but Next.js's own caching is the real culprit here. Start with cache: 'no-store' for immediate relief, then implement proper revalidation for production!
Show original thread7 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.