-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial cache reset #29
Comments
I think the most elgant way would be to implement a deletion QL, where we can select with a regular graph query what we want to delete from the cache |
Any movement on this? |
I'm just curious, I see caching issues similar to this one staying unresolved for the past 2 years. That wouldn't have been a problem if these features weren't basic, but they are.(e.g. update/invalidate cache after deletion) My question is, should developers hope for any standard solutions provided by Apollo in the comming weeks/months or keep on using hacks? I hope this doesn't come off the wrong way, Apollo seems to be doing great work overall! |
100% agreed with @zenVentzi . Not having any cache invalidation / eviction is very inconvenient |
I'd think this was a no-brainer feature. |
Interested to know if there is a hacky workaround, also running into this issue |
Cache eviction and garbage collection is being worked on for apollo-client v3: apollographql/apollo-client#5310 |
I am also looking for a hacky workaround... I've got the exact same problem in my application. |
I had the same issue and my hacky workaround was to clear cache data by query name and refetch: const updateMutation = useUpdateMutation()
updateMutation({
variables: { filters: newFilters },
update: deleteCacheForQuery('allItems'),
refetchQueries: ['allItems']
})
...
const deleteCacheForQuery = (queryName: string) => (proxy: DataProxyExt) => {
const cache = proxy.data
if (cache) {
Object.keys(cache.data || {})
.filter(name => name.startsWith(queryName) || name.startsWith(`$ROOT_QUERY.${queryName}`))
.forEach(name => cache.delete(name))
}
} This is an example with react-hooks but I'm sure you can find Be aware that import { DataProxy } from 'apollo-cache'
interface DataProxyExt extends DataProxy {
data?: {
data?: { [key: string]: string }
delete: (key: string) => void
}
} |
How about delete cache by operation name? |
A simple way to reset the cache for a specific query is to call the query again with fetchPolicy: 'network-only'. GraphQL fetches data from API and updates the cache after results are received. |
Cache eviction / garbage collection is now supported - thanks! https://www.apollographql.com/docs/react/caching/garbage-collection/ |
This features comes from the now closed issue: apollographql/apollo-client#3564. I'll paraphrase the original author as he's quite precise in its request:
The text was updated successfully, but these errors were encountered: