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

RxCache returning only first value of an Observable stream #136

Open
apexkid opened this issue Dec 16, 2018 · 1 comment
Open

RxCache returning only first value of an Observable stream #136

apexkid opened this issue Dec 16, 2018 · 1 comment

Comments

@apexkid
Copy link

apexkid commented Dec 16, 2018

I was able to make RxCache with retrofit work by creating a provider which matches the return type of the retrofit api interface. However, if i first transform the API output to another Observable and try to cache on it, the cache only returns the first object in the stream.

I have a function in my repository like this:

 public Observable<FeaturedUserRecord> getFeaturedUsersFromService(boolean forceAPIReload) {
        Log.v(TAG, "Trying to getFeaturedUsersFromService");

        final Observable<FeaturedUsersResponse> output = apiService.getFeaturedUsers();
        final Observable<FeaturedUserRecord> result = output.flatMapIterable(listRest -> listRest.getData())
                .map(apiEntity -> transformer.transform(apiEntity));

        return result;
    }

I want to cache on the return value of the function instead on the return value of the apiService. Therefore, i created a provider like:

    @ProviderKey("featured-users-cached2")
    @LifeCache(duration = 5, timeUnit = TimeUnit.MINUTES)
    Observable<FeaturedUserRecord> getFeaturedUsersCached2(
            Observable<FeaturedUserRecord> functionOutput, EvictProvider evictProvider
    );

The first time data is loaded, it sends all the records received from the api. However, the cache only returns the first value of the observable stream on subsequent refreshes.

@apexkid apexkid changed the title RxCache and retrofit issue RxCache returning only first value of an Observable stream Dec 16, 2018
@apexkid
Copy link
Author

apexkid commented Dec 16, 2018

Is it the case here that RxCache can cache Observable<List<MyObj>> but it cannot work with Observable<MyObj>?

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

1 participant