villus icon indicating copy to clipboard operation
villus copied to clipboard

clearing cache

Open ensacta opened this issue 4 years ago • 5 comments

how to manualy clear cache on logout when not using "network-only" mode?

ensacta avatar Nov 26 '20 03:11 ensacta

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)
      })
  });

kamaladenalhomsi avatar Nov 26 '20 04:11 kamaladenalhomsi

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.

logaretm avatar Nov 26 '20 09:11 logaretm

I would love to work on this, preparing a PR

kamaladenalhomsi avatar Nov 27 '20 03:11 kamaladenalhomsi

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 avatar Dec 07 '20 12:12 zigomir

@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.

logaretm avatar Dec 09 '20 08:12 logaretm