villus
villus copied to clipboard
clearing cache
how to manualy clear cache on logout when not using "network-only" mode?
I don't think this question is related to the library itself, since results are being saved in the cache storage, you can easily delete cached data using caches.delete()
e.g:
// to delete all cached data:
caches.keys().then(function(keyList) {
keyList.forEach(key => {
caches.delete(keyList)
})
});
Currently, it's not supported, will see what I can do.
@kamaladenalhomsi This lib does have an internal cache that would need clearing in some cases. It's not the native caches API.
I would love to work on this, preparing a PR
I'd also need this. Currently my issue is that after mutation, we should be able to clear the cache to prevent results from stale cache to be returned. Current workaround is to use cachePolicy: 'network-only'...
As a POC I edited villus directly in my node_modules dir and am clearing cache on every mutation. Inside function cachePlugin I do
if (operation.type === 'mutation') {
resultCache = {} // clear cache
}
But this seem too extreme.
@kamaladenalhomsi are you still preparing a PR? @logaretm what would in your opinion be a good cache busting mechanism?
@zigomir You can always build your own cache plugin and add your own cache clearing mechanism. I would say this is the best approach at the moment. You could use the cache.ts code as a starting point.
Another approach is that you could re-create the villus client whenever you want to clear the cache.