nytimes / Store

Android Library for Async Data Loading and Caching

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: isn't fetch() supposed to fall back to cache if network not available

santoshag opened this issue · comments

If the user has data available in cache and if we make the fetch() api call when there is no network, isn't fetch supposed to get data from cache rather than throwing an exception?
If not, do you have any suggestions to accomplish this?

What you are describing is not the default behavior but you can achieve similar functionality using an rx operator to swap in a get call when a fetch fails

store.fetch(key)
  .onErrorResumeNext(store.get(key))
  .subscribe()

Let me know if this works for you :-)

After thinking for sometime, I realized why it is the way it is. We instead used a network helper implemented previously to check for network availability before doing fetch().
The scenario is for user login data, we always want to fetch from network first, if not fallback to cache.
Thanks for clarification @digitalbuddha, closing this issue.