#How to handle old (now) invalid persisted data?

14 messages · Page 1 of 1 (latest)

abstract agate
#

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)

#

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

misty sigil
#

I'd use the cache_buster if you want infinity maxAge

#

yes it busts everything but 🤷‍♂️

abstract agate
#

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.

misty sigil
#

wait a sec are you using the PersistQueryClientProvider or createPersister ?

abstract agate
#

experimental_createQueryPersister

misty sigil
#

hmm

#

there's no way to bust specific queries atm

abstract agate
#

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

misty sigil
#

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

abstract agate
#

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