Clearing cache of all data where the key array starts with specific elements #525
-
The problem I am trying to solve:
All these requests would create separate keys in the cache. The question is when I update the data table (e.g. add a todo) how can I clear all this cache (everything asociated with Potential solution: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I built swr-mutate-many for this use-case, what the lib does is: import { cache } from "swr";
cache.keys().filter(key => key.startsWith(cache.serializeKey(["/api/todos"]).forEach(key => cache.delete(key)) Something like this The serializeKey is required because when using an array as key the final string used to store the data is something like |
Beta Was this translation helpful? Give feedback.
I built swr-mutate-many for this use-case, what the lib does is:
Something like this
The serializeKey is required because when using an array as key the final string used to store the data is something like
arg@"/api/todos"
so you need thatarg@
part at the beginning.