Open ildar2 opened 6 years ago
Same is happening with me.
I had the same when data encrypted
There are three Source types:
MEMORY
,PERSISTENCE
andCLOUD
; I get results from cloud and memory, but after I close app I lose all data: no data returned fromPERSISTENCE
. How can I fix/debug this? Are you solve it? Can you answer me quickly ?
Yeah, I used something else
What method can you use to achieve the same effect, thanks
I've created interface MbCache to store my object (called Dashboard). Implementation can be any persistence lib. then I just manually saved and retrieved it
@Inject
protected MbCache mCache;
@Inject
public DataRepository() {
}
private boolean dashboardCacheValid;
private boolean firstTimeDashboardRequested = true;
public void invalidateDashboardCache() {
//todo for LocalCache
Timber.v("dashboard cache invalidated");
firstTimeDashboardRequested = false;
dashboardCacheValid = false;
}
public Observable<Dashboard> getDashboard(String phoneNum, boolean getNewData) {
Dashboard fromCache = mCache.getDashboard();
if (firstTimeDashboardRequested) {
dashboardCacheValid = fromCache.cacheValid();
firstTimeDashboardRequested = false;
}
if (!fromCache.cacheValid()) invalidateDashboardCache();
if (dashboardCacheValid && !getNewData) {
return Observable.just(fromCache);
} else {
Observable<Dashboard> observableToCache = Observable.concat(Observable.just(fromCache),
mNetworkHelper.getDashboardRaw(phoneNum)
.doOnNext(dashboard -> {
dashboardCacheValid = true;
mCache.putDashboard(dashboard);
}));
return cacheObservable(CACHE_PREFIX_GET_DASHBOARD + phoneNum, observableToCache);
}
}
I've created interface MbCache to store my object (called Dashboard). Implementation can be any persistence lib. then I just manually saved and retrieved it
@Inject protected MbCache mCache; @Inject public DataRepository() { } private boolean dashboardCacheValid; private boolean firstTimeDashboardRequested = true; public void invalidateDashboardCache() { //todo for LocalCache Timber.v("dashboard cache invalidated"); firstTimeDashboardRequested = false; dashboardCacheValid = false; } public Observable<Dashboard> getDashboard(String phoneNum, boolean getNewData) { Dashboard fromCache = mCache.getDashboard(); if (firstTimeDashboardRequested) { dashboardCacheValid = fromCache.cacheValid(); firstTimeDashboardRequested = false; } if (!fromCache.cacheValid()) invalidateDashboardCache(); if (dashboardCacheValid && !getNewData) { return Observable.just(fromCache); } else { Observable<Dashboard> observableToCache = Observable.concat(Observable.just(fromCache), mNetworkHelper.getDashboardRaw(phoneNum) .doOnNext(dashboard -> { dashboardCacheValid = true; mCache.putDashboard(dashboard); })); return cacheObservable(CACHE_PREFIX_GET_DASHBOARD + phoneNum, observableToCache); } }
When I manually clear the application's cache and then retrieve the data from the rxcache again, I will not get a data error
W/System.err: io.rx_cache2.RxCacheException: The Loader provided did not return any data and there is not data to load from the Cache getJsonFromInternet 2019-03-22 11:58:06.117 29792-29792/com.open.filter W/System.err: at io.rx_cache2.internal.ProcessorProvidersBehaviour$5.apply(ProcessorProvidersBehaviour.java:148) 2019-03-22 11:58:06.117 29792-29792/com.open.filter W/System.err: at io.reactivex.internal.operators.observable.ObservableOnErrorReturn$OnErrorReturnObserver.onError(ObservableOnErrorReturn.java:72) 2019-03-22 11:58:06.117 29792-29792/com.open.filter W/System.err: at io.reactivex.internal.observers.BasicFuseableObserver.onError(BasicFuseableObserver.java:100) 2019-03-22 11:58:06.117 29792-29792/com.open.filter W/System.err: at io.reactivex.internal.observers.BasicFuseableObserver.fail(BasicFuseableObserver.java:110) 2019-03-22 11:58:06.117 29792-29792/com.open.filter W/System.err: at io.reactivex.internal.operators.observable.ObservableMap$MapObserver.onNext(ObservableMap.java:59) 2019-03-22 11:58:06.118 29792-29792/com.open.filter W/System.err: at com.jakewharton.retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:51) 2019-03-22 11:58:06.118 29792-29792/com.open.filter W/System.err: at com.jakewharton.retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:37) 2019-03-22 11:58:06.118 29792-29792/com.open.filter W/System.err: at com.jakewharton.retrofit2.adapter.rxjava2.CallObservable.subscribeActual(CallObservable.java:43)
There are three Source types:
MEMORY
,PERSISTENCE
andCLOUD
; I get results from cloud and memory, but after I close app I lose all data: no data returned fromPERSISTENCE
. How can I fix/debug this?