T

tRPC

❓-help

Join Server

Clearing Cache

ZZeph11/24/2022
How do I clear the queryCache for a particular query using the trpc context? If that's not possible, how can I do that using queryClient?
queryClient.getQueryCache().clear()

I've tried the above but it clears the entire cache. I just want to clear the cache of particular key.

Thank you!
UUUnknown User11/24/2022
2 Messages Not Public
Sign In & Join Server To View
ZZeph11/24/2022
Oh I forgot to mention that I would like to clear the cache for an infinite query such that when the user queries for it again, it starts from scratch e.g. just the first 5 results.
ZZeph11/24/2022
But when I used invalidate queries, it seems to refetch all the results that were initially loaded. i.e. if the user loaded 15 results, the refetch would refetch all 15 results which is not what I wanted.
UUUnknown User11/24/2022
Message Not Public
Sign In & Join Server To View
ZZeph11/24/2022
I did the following:

const utils = trpc.useContext()
utils.liked_place.infiniteList.invalidate()
UUUnknown User11/24/2022
Message Not Public
Sign In & Join Server To View
ZZeph11/24/2022
I see! Let me give that a shot! Thank you🤗
ZZeph11/24/2022
Actually, do I have to be more granular? I do want to clear the cache for all liked_place infinite queries.
ZZeph11/24/2022
currently my keys look like this:
[["liked_place","infiniteList"],{"folderId":"7218f699-78a8-4524-b15e-9a6c13e80af5","limit":5,"userId":"13dbca38-063d-4df7-bd1f-72908d1332fe"}]

and the user has several folders. So I just want to clear the entire cache for [liked_place, infinitelist]
UUUnknown User11/24/2022
Message Not Public
Sign In & Join Server To View
ZZeph11/24/2022
oh, I actually want to invalidate the entire liked_place cache, not just the first 5.
UUUnknown User11/24/2022
2 Messages Not Public
Sign In & Join Server To View
ZZeph11/24/2022
Alright! Thanks so much for your patience and help!(: Really appreciate it!