-
Notifications
You must be signed in to change notification settings - Fork 305
Issue with getting cached then fresh data #304
Comments
I can work around this particular issue by checking the network connection before calling
However the point of my question still stands, how can I ensure that cached data is returned when the |
i have the same scenario. my workaround is to use onErrorResumeNext on fetch call and hand it back to get() on error. store.fetch(barCode).onErrorResumeNext(throwable -> store.get(barcode) edit: it's actually already featured on one of the issue here. |
Sorry I'm a bit confused. My understanding is that get would be called first returning your cached data and only after that emission completes your fetch would be called. Could you provide a test case showing what your problem is? I don't see how network would be called before cache in the above example. Maybe a regression happened. |
Actually yeah you are right, it shouldn't happen. I didn't realise I'll put together a small test project to try and reproduce it. |
I have a demo project for you to reproduce the bug. See here. Strangely, I found that I got the expected behaviour (cached data and then onError) if I added a Doesn't work:
Works:
Maybe there is some rx behaviour here that I don't understand. Update: |
@digitalbuddha Hey, have you had a chance to take a look at this? |
The issue is definitely caused by store.get() completing before the cached data has been completely propagated to the Observer. If you add a 100ms delay before you call store.fetch(), this issue does not occur:
|
@jamieadkins95 hey there! i was able to replicate your issue and found that if you set the .networkBeforeStale() on the store builder it will function as you want. The internal logic deals with a single and either emits a value or errors. Will consider alternate approaches. Here is the line of code if you are interested: https://bit.ly/2KP3DFc Also, my apologies on getting back to you. Please let us know if this works. Thank you! |
Thanks for taking a look @brianPlummer! We have usecases where we would like the cached data and also the error so that we can show some data and then an error message to the user. Adding Our latest implementation has moved away from using Something vaguely like this:
This avoids the chain terminating if there is an error fetching fresh data |
We are using the recipe from the wiki to retrieve cached then fresh data:
Under normal conditions this works fine. When fresh data request times out, we get any cached data and then
onError
is called later when the request times out.However I'm running into an issue when the device is in airplane mode. In this case the
fetch
call fails immediately with anUnknownHostException
,onError
is then called and the whole observable chain collapses. Since the failure is immediate, the observable chain collapses before the cached data can be returned. Instead of getting cached data and an error message, we get just an error message.How should I handle this case? Should I be just checking for a network connection before making the request, or is there an approach I can take with Store to address this?
For reference here is how we are currently using Store:
The text was updated successfully, but these errors were encountered: