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

No data saved in PERSISTENCE #130

Open
ildar2 opened this issue Aug 2, 2018 · 7 comments
Open

No data saved in PERSISTENCE #130

ildar2 opened this issue Aug 2, 2018 · 7 comments

Comments

@ildar2
Copy link

ildar2 commented Aug 2, 2018

There are three Source types: MEMORY, PERSISTENCE and CLOUD; I get results from cloud and memory, but after I close app I lose all data: no data returned from PERSISTENCE. How can I fix/debug this?

@UmarBhutta
Copy link

Same is happening with me.

@leejiang1
Copy link

leejiang1 commented Jan 22, 2019

I had the same when data encrypted

@SmallerRiver
Copy link

There are three Source types: MEMORY, PERSISTENCE and CLOUD; I get results from cloud and memory, but after I close app I lose all data: no data returned from PERSISTENCE. How can I fix/debug this?
Are you solve it? Can you answer me quickly ?

@ildar2
Copy link
Author

ildar2 commented Mar 20, 2019

Yeah, I used something else

@ghost
Copy link

ghost commented Mar 20, 2019

What method can you use to achieve the same effect, thanks

@ildar2
Copy link
Author

ildar2 commented Mar 20, 2019

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);
        }
    }

@ghost
Copy link

ghost commented Mar 22, 2019

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)

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

4 participants