Skip to content
This repository has been archived by the owner on Aug 9, 2020. It is now read-only.

Confusing behavior of useExpiredDataWhenNoLoaderAvailable() #7

Closed
vtarantik opened this issue Nov 26, 2016 · 2 comments
Closed

Confusing behavior of useExpiredDataWhenNoLoaderAvailable() #7

vtarantik opened this issue Nov 26, 2016 · 2 comments

Comments

@vtarantik
Copy link

Hi,
I'd like to show the cached data and meanwhile download the new data in the background. If there's no cached data(first run), I simply show No data available TextView. What I tried so far is this:

ReactiveCache reactiveCache = new ReactiveCache.Builder() .diskCacheSize(30) .useExpiredDataWhenNoLoaderAvailable() .using(app.getFilesDir(),new GsonSpeaker()); return reactiveCache;

cacheProvider = reactiveCache.<ContactsList>provider() .lifeCache(5,TimeUnit.SECONDS) .withKey("contacts");

I'm using it like this:
apiInteractor.getContacts() .compose(cacheProvider.readWithLoader()) .subscribeOn(Schedulers.newThread()) .observeOn(mainThread()),

When I disabled the WiFi and reloaded the fragment, I expected the cached data to be emitted but I get the RxCacheException instead. Sorry if I'm missing something, I'm quite new in Rx. I've even tried expirable(false) but with no luck.

Stack trace:

W/System.err: io.rx_cache.RxCacheException: The Loader provided did not return any data and there is not data to load from the Cache contacts W/System.err: at io.rx_cache.internal.ProcessorProvidersBehaviour$6.call(ProcessorProvidersBehaviour.java:156) W/System.err: at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.call(OperatorOnErrorResumeNextViaFunction.java:53) W/System.err: at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$1.call(OperatorOnErrorResumeNextViaFunction.java:50) W/System.err: at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140) W/System.err: at rx.internal.operators.OnSubscribeMap$MapSubscriber.onError(OnSubscribeMap.java:88) W/System.err: at retrofit2.adapter.rxjava.OperatorMapResponseToBodyOrError$1.onError(OperatorMapResponseToBodyOrError.java:52) W/System.err: at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:178) W/System.err: at rx.internal.producers.ProducerArbiter.setProducer(ProducerArbiter.java:126) W/System.err: at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.setProducer(OperatorOnErrorResumeNextViaFunction.java:159) W/System.err: at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) W/System.err: at rx.Subscriber.setProducer(Subscriber.java:205) W/System.err: at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152) W/System.err: at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:248) W/System.err: at rx.internal.operators.OperatorMerge$MergeSubscriber.onNext(OperatorMerge.java:148) W/System.err: at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77) W/System.err: at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:77) W/System.err: at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276) W/System.err: at rx.Subscriber.setProducer(Subscriber.java:211) W/System.err: at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) W/System.err: at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) W/System.err: at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138) W/System.err: at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) W/System.err: at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) W/System.err: at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51) W/System.err: at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) W/System.err: at rx.Observable.unsafeSubscribe(Observable.java:10200) W/System.err: at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94) W/System.err: at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442) W/System.err: at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:137) W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:150) W/System.err: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:264) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) W/System.err: at java.lang.Thread.run(Thread.java:856) W/System.err: Caused by: java.net.UnknownHostException: Unable to resolve host

@VictorAlbertos
Copy link
Owner

In order to show previous cached data, first, there should be data cached, and second, you need to use useExpiredDataWhenNoLoaderAvailable, as you already told me that you are using.

Be sure that there is already cached data, otherwise you will get that exception.

@arkantos1482
Copy link

arkantos1482 commented Feb 13, 2017

I get the sameException.
It seems useExpiredDataWhenNoLoaderAvailable doesn't work.
Everything works until data get expired, after that I receive RxCacheException. (when i check the state of ReactiveCache instance, before expiration there were a record in ReferenceMemoryMap and Disk, but after expiration, those were vanished)

The code:
customerProvider = new ReactiveCache.Builder() .useExpiredDataWhenNoLoaderAvailable() .diskCacheSize(5) .using(context.getCacheDir(), new GsonSpeaker()) .<Customer>provider() .lifeCache(15, TimeUnit.SECONDS) .withKey("CUSTOMER");

getCustomerApi.compose(customerProvider.readWithLoader());

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

No branches or pull requests

3 participants