Skip to content
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

Skip CachedObservableOriginal when no getCacheKey() #258

Merged
merged 1 commit into from
May 5, 2014
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,11 @@ private ObservableCommand<R> toObservable(Scheduler observeOn, boolean performAs
throw new IllegalStateException("This instance can only be executed once. Please instantiate a new instance.");
}

final String _cacheKey = getCacheKey();

/* try from cache first */
if (isRequestCachingEnabled()) {
Observable<R> fromCache = requestCache.get(getCacheKey());
if (isRequestCachingEnabled() && _cacheKey != null) {
Observable<R> fromCache = requestCache.get(_cacheKey);
if (fromCache != null) {
/* mark that we received this response from cache */
metrics.markResponseFromCache();
Expand Down Expand Up @@ -875,10 +877,10 @@ public void call() {
});

// put in cache
if (isRequestCachingEnabled()) {
if (isRequestCachingEnabled() && _cacheKey != null) {
// wrap it for caching
o = new CachedObservableOriginal<R>(o.cache(), this);
Observable<R> fromCache = requestCache.putIfAbsent(getCacheKey(), o);
Observable<R> fromCache = requestCache.putIfAbsent(_cacheKey, o);
if (fromCache != null) {
// another thread beat us so we'll use the cached value instead
o = new CachedObservableResponse<R>((CachedObservableOriginal<R>) fromCache, this);
Expand Down