Skip to content

1.x: Rename cache(int) to cacheWithInitialCapacity(int) #3498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3664,6 +3664,15 @@ public final Observable<T> cache() {
return CachedObservable.from(this);
}

/**
* @see #cacheWithInitialCapacity(int)
* @deprecated Use {@link #cacheWithInitialCapacity(int)} instead.
*/
@Deprecated
public final Observable<T> cache(int initialCapacity) {
return cacheWithInitialCapacity(initialCapacity);
}

/**
* Caches emissions from the source Observable and replays them in order to any subsequent Subscribers.
* This method has similar behavior to {@link #replay} except that this auto-subscribes to the source
Expand All @@ -3689,14 +3698,17 @@ public final Observable<T> cache() {
* <dt><b>Scheduler:</b></dt>
* <dd>{@code cache} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
* <p>
* <em>Note:</em> The capacity hint is not an upper bound on cache size. For that, consider
* {@link #replay(int)} in combination with {@link ConnectableObservable#autoConnect()} or similar.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

*
* @param capacityHint hint for number of items to cache (for optimizing underlying data structure)
* @param initialCapacity hint for number of items to cache (for optimizing underlying data structure)
* @return an Observable that, when first subscribed to, caches all of its items and notifications for the
* benefit of subsequent subscribers
* @see <a href="http://reactivex.io/documentation/operators/replay.html">ReactiveX operators documentation: Replay</a>
*/
public final Observable<T> cache(int capacityHint) {
return CachedObservable.from(this, capacityHint);
public final Observable<T> cacheWithInitialCapacity(int initialCapacity) {
return CachedObservable.from(this, initialCapacity);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rx/ObservableTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public void run() {
}
}).start();
}
}).cache(1);
}).cacheWithInitialCapacity(1);

// we then expect the following 2 subscriptions to get that same value
final CountDownLatch latch = new CountDownLatch(2);
Expand Down