Skip to content
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

Clearing cache #281

Closed
zluiten opened this issue Apr 14, 2022 · 5 comments
Closed

Clearing cache #281

zluiten opened this issue Apr 14, 2022 · 5 comments

Comments

@zluiten
Copy link

zluiten commented Apr 14, 2022

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?

@zluiten zluiten changed the title Clear data Clearing cache Apr 14, 2022
@tochoromero
Copy link
Contributor

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

@mv-go
Copy link

mv-go commented Nov 18, 2022

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

@darrenjennings
Copy link
Contributor

@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

@matthew-dean
Copy link

I also need something like this. See: #352

@matthew-dean
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants