Global cache keys #2814
Unanswered
ianschmitz
asked this question in
Ideas
Replies: 1 comment
-
I think all you would need to do to get there is prefix all your queries with that information, and query key factories can help with that: https://tkdodo.eu/blog/effective-react-query-keys if the first entry in all query keys is the user-id of the logged in user, you can act on that. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Howdy!
I was curious if there's any current support or plans for supporting global cache keys that would be applied to all queries for a given
QueryClient
?The primary use case i'm thinking of is providing some global context to all queries that should invalidate cached results if it changes. For example the authenticated user's unique id or email. If the current user changes, the cache for the previous user shouldn't be used.
I could see this becoming much more important when persistors such as https://react-query.tanstack.com/plugins/createWebStoragePersistor become mainstream. Perhaps the cache invalidation/eviction would be on the developer to evict the persisted storage if the current user changes?
Beta Was this translation helpful? Give feedback.
All reactions