I am using the tanstack query's persist plugin to persist queries on filesystem. What's a proper approach for handling old data (coming from an API) missing fields that are now available in the API?
Should I just consider all new fields as optional and check for their existence before rendering?
Should I just invalidate the persisted cache? (I'd rather avoid this, as I cannot seem to cache bust only 1 query, I have to bust the whole cache when 1 singular query is wrong)
#How to handle old (now) invalid persisted data?
14 messages · Page 1 of 1 (latest)
Ideally, I want to keep maxAge: Infinity, while keeping some sort of option to invalidate entries that are not valid anymore
Also, I am using the experimental createPersister API
I'd use the cache_buster if you want infinity maxAge
yes it busts everything but 🤷♂️
Just wondering, could there be a per query cache_buster in the future? As, with this experimental API, I know that queries are persisted individually. Would be nice to also be able to bust individually.
wait a sec are you using the PersistQueryClientProvider or createPersister ?
experimental_createQueryPersister
I literally yesterday moved from PersistQueryClientProvider to the experimental one, in the past I had some issues with it (the experimental one), but i think they were caused by me setting retry: false as a default option, I changed it to retry: 1, so queries do not fail if no cache is present and instead they remain pending
you could implement your own storageand have getItem return undefined for cases where you know you want to cache bust
but you'd also need to call removeItem maually then
yeah, ig I'd set some sort of key in the query meta and compare the cached one with the current one somehow to remove the query