Question about getServerSideProps caching behavior in Next.js #85127
-
|
Hi 👋 I’m experimenting with getServerSideProps and noticed that sometimes the data seems to be cached longer than I expected. Thanks in advance for any guidance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
|
By default, getServerSideProps shouldn’t cache responses on the server each request should run the function anew. However, caching can happen at a few layers: If you want to enforce fresh data, you can set cache headers in your response, for example: } This ensures that every request fetches fresh data and nothing is cached. |
Beta Was this translation helpful? Give feedback.
By default, getServerSideProps shouldn’t cache responses on the server each request should run the function anew. However, caching can happen at a few layers:
• CDN / edge caching: If you’re deploying on Vercel, the edge network might cache some responses unless you set proper headers.
• Browser caching: Make sure your response headers don’t allow client caching if you want fresh data every time.
If you want to enforce fresh data, you can set cache headers in your response, for example:
}
This ensures that every request fetches fresh d…