-
Notifications
You must be signed in to change notification settings - Fork 9
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
Responses with error codes are nevertheless cached until the next dedupe time #23
Comments
Hey there, @eta-orionis! Let's start the other way around. What is the behavior you expected the library to have? Like, your fetcher throws—what's next? |
Thanks @dkzlv! I'm using the store as recommended, but with a
My scenario is:
I expect:
What happens is:
|
@eta-orionis Gotchu! My understanding though is that current behavior is correct, so I probably won't change it, sorry. The basic reason is that errors are part of KV-cache. If you had this store in 20 copies across the app, and you subscribed to them within seconds of each other, it's expected that you don't issue 20 requests. While this is a strange example, that's kind of the guarantee we have, and, as I understand, that's how SWR and react-query work as well. Now, to be completely honest, I haven't really put in a lot of thought into current codebase around error restoration topic. Better error handling (e.g., separate In the meantime you can actually work around it pretty easily, if you think it's better for your specific case. The most obvious one would be to instantly invalidate this key if you got an error: const $store = createFetcherStore([$someOtherStore], { dedupeTime: 3600*1000 });
onSet($store, ({ newValue }) => {
if(newValue.error) $store.invalidate();
}) That will basically immediately mark this cache as stale. It won't trigger the refetch (and it shouldn't, that would be DDoSing your server), but it will solve your problem with long-living errored cache. Will that work for you for now? P.S. |
Thanks @dkzlv ! (Thanks for the other suggestions! When I'm finished with this I will probably make a pull request for updating the docs too, as your suggestion should, IMHO, be in the recipes.) |
@eta-orionis You're actually right. The reason is that Here's a repro of your case. Now, ID1 always fetches successfully, and As a temporary solution you can just set the timeout to some appropriate value (say, 4000?). Instead of using That's a bit of a detour for you, I understand, and hopefully I'll find some time to make decent error handling/timeouting/long-waiting solutions there. For the time being I'll close the issue, and current behavior is not a bug, but rather "a-lack-of-a-feature" 😂 Cheers! |
Hello,
Using v0.2.8
My fetcher code:
If the server returns an error code, e.g. 500, this url will not be fetched again until the
dedupeTime
has passed, even though the server might have recovered meanwhile.I expected that only OK responses get cached. Is there any way to make sure that OK responses are cached, but not errors?
The text was updated successfully, but these errors were encountered: