RxCache
RxCache copied to clipboard
RxCache returning only first value of an Observable stream
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.
Is it the case here that RxCache can cache Observable<List<MyObj>>
but it cannot work with Observable<MyObj>
?