
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeI can see the issue! You're fetching data but getting stale content even though it's updated in the Studio. This is a common caching issue with Sanity's CDN, and there are a few solutions.
The main problem is that Sanity's Content Lake uses a CDN that caches responses for performance. Your force: true parameter isn't actually a valid Sanity client option, so it's not doing anything to bypass the cache.
Here are the proper solutions:
perspective parameter (Recommended)The perspectives feature lets you control which version of content you're querying. By default, you might be hitting cached published content. Try adding the perspective parameter to your client configuration or query:
const getUserCart = async (req, res) => {
try {
const currentUserId = req.userInfo.userId;
const carts = await client.fetch(
`*[_type == "carts" && userId == $userId]`,
{
userId: currentUserId,
},
{
perspective: 'previewDrafts', // or 'published' depending on your needs
}
);
res.json(carts);
} catch (error) {
console.log({ message: "Failed to get user cart" });
}
};Note: As of API version 2025-02-19, the default perspective changed to published (previously it was raw). If you need the absolute latest data including drafts, use previewDrafts.
If you need real-time data and want to bypass the CDN entirely, configure your client with useCdn: false:
import { createClient } from '@sanity/client';
const client = createClient({
projectId: 'your-project-id',
dataset: 'your-dataset',
useCdn: false, // Bypass CDN for fresh data
apiVersion: '2025-02-19',
token: 'your-token', // Required for authenticated requests
});If you're building serverless endpoints that need real-time data, consider using Sanity Functions instead of external API routes. They have native integration with the Content Lake and better performance for real-time data access.
When you see updated content in the Studio but stale data in your fetch, it's because:
Setting useCdn: false or using the appropriate perspective should resolve your issue!
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store