Skip to content

Commit 1bb0c21

Browse files
Javadocs for cache operator
1 parent d429110 commit 1bb0c21

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,8 +3361,6 @@ public final <B> Observable<List<T>> buffer(Observable<B> boundary, int initialC
33613361
* {@code subscribe} method.
33623362
* <p>
33633363
*
3364-
* <!-- IS THE FOLLOWING NOTE STILL VALID??? -->
3365-
*
33663364
* <em>Note:</em> You sacrifice the ability to unsubscribe from the origin when you use the {@code cache}
33673365
* Observer so be careful not to use this Observer on Observables that emit an infinite or very large number
33683366
* of items that will use up memory.
@@ -3379,10 +3377,29 @@ public final Observable<T> cache() {
33793377
}
33803378

33813379
/**
3382-
* {@code cache} with initial capacity.
3380+
* Caches emissions from the source Observable and replays them in order to any subsequent Subscribers.
3381+
* This method has similar behavior to {@link #replay} except that this auto-subscribes to the source
3382+
* Observable rather than returning a {@link ConnectableObservable} for which you must call
3383+
* {@code connect} to activate the subscription.
3384+
* <p>
3385+
* <img width="640" height="410" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/cache.png" alt="">
3386+
* <p>
3387+
* This is useful when you want an Observable to cache responses and you can't control the
3388+
* subscribe/unsubscribe behavior of all the {@link Subscriber}s.
3389+
* <p>
3390+
* When you call {@code cache}, it does not yet subscribe to the source Observable and so does not yet
3391+
* begin cacheing items. This only happens when the first Subscriber calls the resulting Observable's
3392+
* {@code subscribe} method.
3393+
* <p>
33833394
*
3384-
* @param capacity
3385-
* initial cache size
3395+
* <em>Note:</em> You sacrifice the ability to unsubscribe from the origin when you use the {@code cache}
3396+
* Observer so be careful not to use this Observer on Observables that emit an infinite or very large number
3397+
* of items that will use up memory.
3398+
* <p>
3399+
* {@code cache} does not operate by default on a particular {@link Scheduler}.
3400+
*
3401+
* @warn description may be out-of-date
3402+
* @param capacity hint for number of items to cache (for optimizing underlying data structure)
33863403
* @return an Observable that, when first subscribed to, caches all of its items and notifications for the
33873404
* benefit of subsequent subscribers
33883405
* @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#cache">RxJava Wiki: cache()</a>

0 commit comments

Comments
 (0)