Next.js Discord

Discord Forum

is there a way to completely disable cache in nextjs

Unanswered
Common Moorhen posted this in #help-forum
Open in Discord
Common MoorhenOP
hey is there a way to completely disable cache in nextjs

16 Replies

@Common Moorhen hey is there a way to completely disable cache in nextjs
follow the opt out methods documented [here](https://nextjs.org/docs/app/building-your-application/caching).

for the router cache specifically, it can be opted out with the [experimental.staleTimes config option](https://nextjs.org/docs/app/api-reference/next-config-js/staleTimes).
@Common Moorhen hey is there a way to completely disable cache in nextjs
you can also enter the [draftmode](https://nextjs.org/docs/app/api-reference/functions/draft-mode) to completely disable all cache very easily. However that isn't the recommended way. As joulev said, use the opt out methods
Common MoorhenOP
i am using apollo that most likely uses fetch under the hood, but turning off cache from there didnt help, I want to globally turn off cache similar to "export cosnt revalidate = 0"
so nextjs most likely changes cache control and also turns off storing cache internally by itslef
Common MoorhenOP
ideal approach i am looking for is to have some trigger ENV state for enabling/disabling the cache
Common MoorhenOP
so setting staleTime { dynamic: 0 } should help?
I don’t know what kind of cache you are trying to disable, so I don’t know. Have you tried it?
Common MoorhenOP
internal nextjs cache, but when i set it to 30 it still have the same cache-control, should this be changed as well?
What is this internal cache that you are talking about?
Common MoorhenOP
the one that uses nextjs stored in .next folder by default, if i explained myself incorrectly iam sorry
.next is not the cache. It stores build output, bundle files, and literally everything that next build spits out that next start needs to run. You want to remove the folder? Impossible.
Common MoorhenOP
so then what does the revalidate: 0; do to my current page.tsx? it works as i would expect it to. it disables nextjs cache automatically caching requests
if you know what i mean
It opts you out of the full route cache https://nextjs.org/docs/app/building-your-application/caching#opting-out-2.

Yes that sounds confusing, but basically all that does is it tells nextjs to run your page at every request.