Next.js Discord

Discord Forum

Disable router cache completely

Answered
Belgian Hare posted this in #help-forum
Open in Discord
Belgian HareOP
Hi, is it possible to disable caching when switching routes? like if i made a change on abc page and switch to previous page xyz then switch back to abc again, abc still has old data even after revalidation.

I'd like to turn off cache while switching routes completely, our site isnt static.
Answered by joulev
use proper revalidation methods (revalidatePath/revalidateTag/router.refresh) instead
View full answer

25 Replies

use proper revalidation methods (revalidatePath/revalidateTag/router.refresh) instead
Answer
@joulev > Disable router cache completely no, it's impossible.
Belgian HareOP
oh boi :/
ive to do it for whole site
then use client-side rendering
use tanstack query and route handlers
Belgian HareOP
ugh that'd be too much, whole codebase's using server stuff :lolsob:
you are simply using cache the wrong way. there is no way to disable the router cache.
Belgian HareOP
shouldnt force-dynamic work?
force-dynamic doesn't change anything if the route is already dynamic
@joulev you are simply using cache the wrong way. there is no way to disable the router cache.
Belgian HareOP
i just want new data to be displayed when switching routes, our tester wont understand this
could use date in the href but thats more of a workaround :lolsob:
tell them that's a feature to reduce load on the server
not a bug
you technically can just patch nextjs to remove the router cache. i wouldn't recommend that though unless you know what you are doing
Belgian HareOP
he wont get it, old data shown on previously visited pages is annoying
or is it possible to make Link not use cache?
no as i said, you are just wishing for the impossible. if you don't patch nextjs, you cannot remove the router cache and that's a hard fact you have to accept
and that works
@joulev use proper revalidation methods (`revalidatePath`/`revalidateTag`/`router.refresh`) instead
use these functions, how to do that depends on your code
but use those functions to remove the cache
@joulev use these functions, how to do that depends on your code
Belgian HareOP
working all good :sunglasses_1: