Can't disable page caching #67917
Replies: 4 comments 7 replies
-
Try to isolate you POST request and GET request into two file https://github.com/HellYeahOmg/revalidate-test/blob/main/src/app/api/route.js Because GET are cache by default but once you add POST method, the cache is disabled Then import {RevalidateButton} from "@/app/revalidateButton";
export default async function Home() {
const data = await fetch('http://localhost:3000/api', { next: { tags: ['data'] } }).then(res => res.json())
return (
<main>
<div className={'mb-8'}>
<p>data list:</p>
{data.map(item =>
<div key={item.id}>
<p>{item.name}</p><p></p>
</div>)}
</div>
<RevalidateButton></RevalidateButton>
</main>
);
} |
Beta Was this translation helpful? Give feedback.
-
Hi, I think the GET function is getting statically optimized: https://nextjs.org/docs/app/building-your-application/routing/route-handlers#opting-out-of-caching Try with |
Beta Was this translation helpful? Give feedback.
-
So according to https://nextjs.org/docs/app/building-your-application/caching#invalidation-1 export const dynamic = 'force-dynamic'; But the second issue with long async fetching in the background is not working, even with revalidate functions |
Beta Was this translation helpful? Give feedback.
-
Hello, guys It seems I know what you're talking about – in Therefore, you probably want to disable the non-server-side caching managed by the This is controlled by another setting, specifically:
You can read more about it here: https://nextjs.org/blog/next-15-rc#client-router-cache-no-longer-caches-page-components-by-default |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys, I'm having a hard time understanding what is wrong here. I made a simple repo: https://github.com/HellYeahOmg/revalidate-test
Main page has a get request for some items, the second page has a form to add items. After submitting the form i expect to see the updated result on the main page.
I added every possible disabling cache option i could, but it still doesnt work unless i fire router.request() or revalidatePath(). Why so?
Anyways, this was the basic question i got after playing with caching. My main issue is https://github.com/HellYeahOmg/revalidate-test/tree/long-async-request
While sending a heavy request from the main page, users can navigate to other pages, and in that case even revalidatePath (or revalidateTags) doesnt help...
"next": "^14.2.5"
Beta Was this translation helpful? Give feedback.
All reactions