admin管理员组文章数量:1242825
I'm working on a Next.js project that uses an external API for a marketplace feature. The marketplace automatically closes at a specific time, and when it does, the API response changes from: { success: true } → { success: false }
To improve performance, I set revalidate: 600 in my fetch to cache the response for 10 minutes. However, after the marketplace closes, the API response remains { success: true }, likely due to the cache.
From what I’ve found, possible solutions include disabling caching or using On-Demand Revalidation. But since the API doesn't provide any way to know when the marketplace will close, I can’t proactively trigger revalidation.
Is there a better approach to handle this situation?
Update
To provide more context, here’s the TypeScript code for fetching the marketplace status:
const getMarketspace = async ({
shopId,
}: {
shopId: string;
}): Promise<APIResponse> => {
const res = await fetch("/v/layouts", {
method: "POST",
headers: {
...defaultHeaders,
},
body: JSON.stringify({
shopId,
}),
next: {
revalidate: 600,
}
});
// ... Other Code
}
For example, if the marketplace closes at February 17, 2025, 23:59, and I make a request at February 18, 00:00, the API correctly responds with:
{ "success": false }
However, even if I call the same fetch hours later, such as at February 18, 12:00, the response is still:
{ "success": true }
This happens even though the cache should have expired long ago based on the revalidate: 600 setting.
本文标签: How to handle API changes with Nextjs revalidate when timing is unpredictableStack Overflow
版权声明:本文标题:How to handle API changes with Next.js revalidate when timing is unpredictable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740150081a2232495.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论