Skip to content
Discussion options

You must be logged in to vote

I haven't tried that yet, but what you are looking for sounds like the persistQueryClient plugin. I would go to v4 for this, as we've improved the api: https://react-query-beta.tanstack.com/plugins/persistQueryClient

  • write a persister for redis (I've never worked with redis, but if you have an async read and an async write method, you should be good to go)
  • during getServerSideProps:
    • create a new queryClient
    • call await persistQueryClientRestore to load from the external storage
    • call await prefetchQuery as per usual, but pass a staleTime to it, so that you'll read data from the cache if its not older than the passed time
    • after that, write back to redis with await persistQueryClientSave
  • c…

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@Shkulipa
Comment options

@TkDodo
Comment options

@ProgerDav
Comment options

@ProgerDav
Comment options

@TkDodo
Comment options

Answer selected by TkDodo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants