Persist some parts of the queryCache to localstage
I have a pretty basic shoppinglist app where data is split it ints volatility:
ingredients and recipes change infrequently, while the shoppinglist itself does changes often.
Is it possible to hold the recipes and ingredients in local storage for a long time (e.g 7d) but prevent the shoppinglist from being persisted that long?
Since I didn't see anything obvious in the queryClient or persister, I think the easiest choice is to have 2 queryClients differenty configured, one "long term" and one "short term"? The long term one would have proper localStorage persistence.
Is this advisable? Am I inadvertenly walking into a trap? Any alternatives?
8 Replies
rival-black•2y ago
You can filter down what to persist with the PersistQueryClientProvider
With the dehydrateOptions
multiple-amethystOP•2y ago
Cool yeah, that lets make make a decision based on the key.
I guess due to how the typesystem is setup, there is no way to set an option on the query itself?
rival-black•2y ago
that's what the new
experimental_createPersister
is for.
you can pass it to a single query and then this one will be persisted on its ownmultiple-amethystOP•2y ago
Oh very interesting!
I've annoyingly now hit the next wall that I saw described in a length github thread: I have a login mutation that calls
setQueryData(...)
within onSuccess :/multiple-amethystOP•2y ago
GitHub
setQueryData()
should be persisted too, right? · Issue #6310 · Ta...Describe the bug I'm using the new experimental_createPersister like this: import { experimental_createPersister, type AsyncStorage } from "@tanstack/query-persist-client-core"; impor...
rival-black•2y ago
Yes, we're discussing how this should be handled. Feel free to provide your thoughts on the issue
multiple-amethystOP•2y ago
Are unqualified opinions welcome to? I think most had been said. I can give insight from an unknowing user 🤷♂️
rival-black•2y ago
sure
I mean you have a use-case, so it would be good to hear how you would like it to work 🙂