-
On my page I want to display public investments. I'm using hydration and I'd like to cache this request for like 3h or so. So I'm modifying data in DB to see if I get old results or new ones, but I always get new ones. Therefore, it seems like it is never cached. _app.js
page.js
I'm probably doing some random mistake but I've read the documentation and defaults and still can't get it to work... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Beta Was this translation helpful? Give feedback.
if you prefetch data on the server, it will always run, because you create a
new QueryClient()
ingetServerSideProps
. The queryClient holds the cache, and a new client means an empty cache. So passing staleTime there is likely irrelevant. So the caching will work, but only on the client. If you prefetch on the server, every request will refetch. The only way to also cache that would be to setup server-side caching, e.g. with redis, and maybe use the persisters to write to there. That is simply because the react-query cache is an in-memory cache. You can theoretically create the QueryClient outside ofgetServerSideProps
, but then it will be shared between users and requests, and it's bas…