June 2017
Intermediate to advanced
400 pages
8h 44m
English
When you want to cache all emissions indefinitely for the long term and do not need to control the subscription behavior to the source with ConnectableObservable, you can use the cache() operator. It will subscribe to the source on the first downstream Observer that subscribes and hold all values indefinitely. This makes it an unlikely candidate for infinite Observables or large amounts of data that could tax your memory:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable<Integer> cachedRollingTotals = Observable.just(6, 2, 5, 7, 1, 4, 9, 8, 3) .scan(0, (total,next) -> total + next) .cache(); cachedRollingTotals.subscribe(System.out::println); }}
You can also call cacheWithInitialCapacity() ...
Read now
Unlock full access