Using cookies in middleware disables cacheing for the whole application?
Answered
MarkMiklos posted this in #help-forum
As mentioned in the question is cookies used in the middleware disables cacheing?
Answered by Arinji
26 Replies
nope, your fetch requests in the middleware arent cached and cant be cached
but your site still has caching
thats how you can cache your fetch requests in the middleware
@MarkMiklos
I see, then what would u say about that that I have a middleware that is basically calling a getSession function that gets the token from the cookie, which was set by the login function above, and on all of my routes console does say cache: SKIP
ok so @MarkMiklos middleware runs on every request
since as i mentioned before, fetches from your middleware directly are never cached'
hence the skips
makes sense?
it does yeah
@MarkMiklos it does yeah
so if you want to cache stuff, we do a workaround
where we make a server action, and call that server action.. so technically its not your middleware making the request, its your middleware making a request to a server action which makes the request
obviously this makes the action a public endpoint as we were disucssing on #discussions but thats what i do
I see that make sense now, i was so confused 😄
No worries, its a weird thing
Some of nextjs stuff are...questionable
Next 14 is a weird thing on its own
@ᴉuɐpɹɐɐ any reason why middleware dosent cache stuff?
@MarkMiklos Next 14 is a weird thing on its own
mhm xD
wait for alfon if he knows why middleware dosent cache stuff
wait for alfon if he knows why middleware dosent cache stuff
alfon the cache guy
Sure I'll wait, then mark the answer, thanks though
yup :D
Answer
Thanks