For security reasons, I have to include a header in all API requests whose value is dynamic and never repeated.
The problem is that if I make two requests to the same url, but with two different values in this header, NextJS understands that they are two different requests and caches them separately.
GET /posts Headers: { x: 123 }
GET /posts Headers: { x: 456 }
I guess NextJS serializes the requests and uses this as the cache key. How can I make it not include the headers (or just my x header) when doing this and only take the url and the parameters?
I tried to find some settings in the documentation: https://nextjs.org/docs/app/building-your-application/caching.
Keep in mind that what I am looking for is to configure the Data Cache of the requests, not the Full Route Cache of the pages or routes, so export const dynamic = "force-static"
and things like that won’t work.
Thanks for your help!
Samuel Rodríguez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.