You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think having an option to invalidate tags without refetching for subscribers would be great.
I work on a cardano wallet and was looking for something like this for our adahandle support (adahandles are basically shortcodes for addresses that are minted / powered by NFTs).
A user could type an adahandle to send their coins to in the receive bar. That dispatches an initiate call to our api, which we await for the result.
All is well at this point. The problem arises that ownership of these shortcodes can change from minute to minute, or they can be created on-chain if they didn't exist before. Therefore, we don't want to cache the result for very long. However, we also don't want to continuously requery all handles that were ever searched, as this would bog down the server that indexes these handles.
At first, I tried setting a timeout to invalidate the tags after awaiting onQueryFulfilled. However, this would immediately trigger a refetch for that handle (even if the user was no longer searching for that handle's underlying crypto address).
The solution I resorted to was basically along the lines of
And then the onQueryFulfilled callback had a setTimeout that invalidated the tags result for that handle after a certain amount of time.
I had to handle the subscriptions like this, because otherwise invalidateTags triggers an infinite loop of refetches for a potentially irrelevant query since the invalidateTags creates a subscription to cleanly await it. However, if I set subscribe to false, awaiting the dispatch does not await the actual data from the response.
My desired behavior was:
Query handle
Cache that handle for 5 minutes
Remove from cache after 5 minutes
If user requeries that handle, refetch.
My guess is useQuery with a pollingInterval would have been best suited for this, though my app totally crashed when I tried using this arrangement so I had to revert to dispatching initiate calls.
We've got utils to add and update cache entries, but we don't have one that would remove a specific cache entry by key.
We've had a couple requests for something like this recently, so worth discussing.
Lenz had these thoughts in chat:
What specific use cases do people have for wanting to manually remove a cache entry?
The text was updated successfully, but these errors were encountered: