Are POST requests cached?
Answered
Orinoco Crocodile posted this in #help-forum
Orinoco CrocodileOP
Hi.
Just wanted to double-check whether
I know they aren't cached inside of route handlers but I'm not sure whether that's also the case outside of them.
Just wanted to double-check whether
POST requests are cached by default by Next.js?I know they aren't cached inside of route handlers but I'm not sure whether that's also the case outside of them.
Answered by Clown
Ok so i just took another look at the documentations and apparently its just server actions and route handlers with POST method that are not cached
7 Replies
@Orinoco Crocodile Hi.
Just wanted to double-check whether `POST` requests are cached by default by Next.js?
I know they aren't cached inside of route handlers but I'm not sure whether that's also the case outside of them.
POST requests are just not cached.Server Actions themselves are essentially a
POST request hence no request is cached when you fetch from them.Orinoco CrocodileOP
@Clown I see, thank you.
Was there a time where this was not the case (i.e. prior to server actions)? Because I saw this GitHub discussion: https://github.com/vercel/next.js/discussions/56361#discussioncomment-7175600 and it quotes the following from the docs at the time:
However I don't see that in the current docs.
Was there a time where this was not the case (i.e. prior to server actions)? Because I saw this GitHub discussion: https://github.com/vercel/next.js/discussions/56361#discussioncomment-7175600 and it quotes the following from the docs at the time:
fetch requests that use the POST method are also automatically cached. Unless it's inside a Route Handler that uses the POST method, then it will not be cached.However I don't see that in the current docs.
Orinoco CrocodileOP
Also is there an easy way to test what's being cached and what isn't? Or do I have to build the app and test manually?
Ok so i just took another look at the documentations and apparently its just server actions and route handlers with POST method that are not cached
Answer
So technically if you POST to an external API directly in the component it should cache
Orinoco CrocodileOP
Thanks @Clown!