Next.js Discord

Discord Forum

How to cache POST fetch call response & avoid re-calling the server on every page navigation

Unanswered
Lhasa Apso posted this in #help-forum
Open in Discord
Lhasa ApsoOP
Hey, I am trying to use pure Next.js fetch call to fetch data from GraphQL endpoint with pure Next.js caching.

Is it possible to cache the response from the fetch & avoiding recalling the function when revisiting the same page (or going on another with same fetch query).

Good start is to wrap it with React's cache function to avoid recalling it multiple times on the same page, but what about the navigation? I want to cache for certain amount of time, but per session meaning just for the client & when the page is refreshed all new data come in.

Goal is to avoid using 3rd party libraries like Tanstack Query & use pure fetch & Next.js.

Is this possible? Couldn't find any reference in docs. Thanks!

1 Reply

Lhasa ApsoOP
After some searching it looks like that client side caching for navigations is not something that Next.js solves & I should use Tanstack Query for this..? 🤷‍♂️