Skip to content

What is the point of maxAge in PersistQueryClientProvider? #5169

Answered by louis-young
lisherwin asked this question in Q&A
Discussion options

You must be logged in to vote

Hi 👋

This is explained to some degree here: https://tanstack.com/query/v4/docs/react/plugins/persistQueryClient#how-it-works

IMPORTANT - for persist to work properly, you probably want to pass QueryClient a cacheTime value to override the default during hydration (as shown above).

If it is not set when creating the QueryClient instance, it will default to 300000 (5 minutes) for hydration, and the stored cache will be discarded after 5 minutes of inactivity. This is the default garbage collection behavior.

It should be set as the same value or higher than persistQueryClient's maxAge option. E.g. if maxAge is 24 hours (the default) then cacheTime should be 24 hours or higher. If lower than…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@lisherwin
Comment options

@louis-young
Comment options

Answer selected by lisherwin
Comment options

You must be logged in to vote
2 replies
@TkDodo
Comment options

@garthendrich
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants