Kong / swrv

Stale-while-revalidate data fetching for Vue

Home Page:https://docs-swrv.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clearing cache

zluiten opened this issue · comments

Is there a way to clear all cached data? Say f.e. when a user signs out I feel more comfortable when all data gets cleared.

Any recommendations?

This is something we also need mainly for unit testing. We need to be able to clear the cache beforeEach test.

commented

Hey guys! Any plans to implement this?

We've ran into the issue when

  • user1 loads some data
  • user1 logs out
  • user2 logs in
  • user2 gets data from user1 until revalidation happens

@mv-go would strongly consider keying off your user-id if sessions/cache calls are shared among browser sessions. You could achieve this by wrapping your useSwrv hook calls into a wrapper function that prefixes the user id keys, something like: #91 (comment). Would be cool to grab the cache to clear it like swr does: https://swr.vercel.app/docs/advanced/cache#access-to-the-cache

I also need something like this. See: #352

A workaround I came up with:

import Cache from 'swrv/dist/cache'

let cache = new Cache()

export default {
  get() {
    return cache
  },
  reset() {
    cache = new Cache()
  }
}

Then set the cache option like:

{
  cache: FetchCache.get()
}