Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Ability to manually clear a cache #25

Open
timcosta opened this issue Nov 15, 2019 · 5 comments
Open

Ability to manually clear a cache #25

timcosta opened this issue Nov 15, 2019 · 5 comments
Labels
enhancement New feature or request

Comments

@timcosta
Copy link

Hello!

Thanks for this great library. It's been super helpful and works well.

I'm wondering if its going to be possible ever to trigger a manual cache clear. Say we are loading a user profile on page load. That data doesn't change often, and can be cached. If a user updates their profile though, we will need the ability to clear the cached response in order to trigger a refetch.

Hope this makes sense as a use case, and thanks again!

@quisido quisido added the enhancement New feature or request label Nov 15, 2019
@quisido
Copy link
Collaborator

quisido commented Nov 15, 2019

There are no plans for it currently. I think with concurrent React hopefully so close to launch that they will cover this use case. Concurrent React will likely render this package obsolete.

While I don't intend to do it myself given the unknown of when concurrent React will be publicly available, I would welcome a PR that handles this.

@ryanberckmans
Copy link

@AidanNichol
Copy link

I've just been playing with this and after some false attempts I came up with a simple to implement solution. I added clear, a function to remove this entry from the cache (copied from the setTimeout function), to the metadata. So in those cases where I need this function I just need to request the metadata and I'm sorted.
I'll look at producing a PR.

@AidanNichol
Copy link

AidanNichol commented Jun 18, 2020

How does this look?

master...ryanberckmans:f11e2b43a57bb314f7aa45aae56acf3f45d3076c

How would you use this? I made a normal call to get my data and then wanted to clear the cache because I've done an update. I found that if I tried a second call of useFetch with the flag to clear the cache it would be in some conditional part of my code and so fails one of the rules of hooks.

@ryanberckmans
Copy link

ryanberckmans commented Jun 18, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants