Class OnSubscribeCache<T>

  • Type Parameters:
    T - the cached value type
    All Implemented Interfaces:
    Action, Action1<Subscriber<? super T>>, Function, Observable.OnSubscribe<T>


    public final class OnSubscribeCache<T>
    extends Object
    implements Observable.OnSubscribe<T>
    This method has similar behavior to Observable.replay() except that this auto-subscribes to the source Observable rather than returning a connectable Observable.

    This is useful with an Observable that you want to cache responses when you can't control the subscribe/unsubscribe behavior of all the Observers.

    Note: You sacrifice the ability to unsubscribe from the origin when you use this operator, so be careful not to use this operator on Observables that emit infinite or very large numbers of items, as this will use up memory.

    • Field Detail

      • source

        protected final Observable<? extends T> source
      • cache

        protected final Subject<? super T,? extends T> cache
    • Constructor Detail

      • OnSubscribeCache

        public OnSubscribeCache(Observable<? extends T> source)
      • OnSubscribeCache

        public OnSubscribeCache(Observable<? extends T> source,
                                int capacity)