Title: fetch() docs unclear about caching behavior for POST requests #84546
Replies: 4 comments 1 reply
-
Hi, yes, I've been wanting to find time to tackle this, #70946 - if you are willing to submit a PR, I'd appreciate that. If you do, make sure to verify the claims in the PR. |
Beta Was this translation helpful? Give feedback.
-
I’ve reviewed the code and confirmed that the POST API requests are not cacheable. Since that’s the case, I can create a PR to update this documentation : https://nextjs.org/docs/app/api-reference/functions/fetch. Reference: POST requests cannot be cached because Reference lines: next.js/packages/next/src/server/lib/patch-fetch.ts Lines 577 to 583 in f52715b next.js/packages/next/src/server/lib/patch-fetch.ts Lines 491 to 493 in f52715b next.js/packages/next/src/server/lib/patch-fetch.ts Lines 451 to 454 in f52715b next.js/packages/next/src/server/lib/patch-fetch.ts Lines 378 to 397 in f52715b |
Beta Was this translation helpful? Give feedback.
-
Sorry, I missed that earlier — yes, next.js/packages/next/src/server/lib/patch-fetch.ts Lines 808 to 813 in 1111200
However, there’s a potential bug: when using the
next.js/packages/next/src/server/lib/patch-fetch.ts Lines 593 to 600 in 1111200
next.js/packages/next/src/server/lib/patch-fetch.ts Lines 696 to 697 in 1111200 To fix this, we need to add proper checks to prevent force-cache from bypassing uncacheable headers, cookies, or methods. Please let me know if I’ve missed anything or if there’s anything else that needs to be addressed. |
Beta Was this translation helpful? Give feedback.
-
@icyJoseph |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
I was reading the fetch() documentation and noticed that it doesn't clearly mention how caching behaves for POST requests.
The docs explain caching options (cache, next.revalidate, etc.) , but it’s not explicit whether these options apply (or are ignored) for POST requests
Non-Goals
Background
The fetch() docs only explain caching for GET requests, leaving it unclear how caching behaves for POST. Some developers use POST for data retrieval (e.g., GraphQL queries or large payloads), so knowing whether options like cache: 'force-cache' or next.revalidate apply is important.
Proposal
It would be helpful to clarify:
Whether caching is supported for POST requests at all.
If not supported, whether the cache option is ignored or throws an error.
Any recommended approach for optimizing repeated POST requests.
This clarification would help developers understand the correct behavior and avoid confusion when using caching options with POST.
Beta Was this translation helpful? Give feedback.
All reactions