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

RxCache returning only first value of an Observable stream #136

@apexkid

Description

@apexkid

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions