Skip to content

Commit

Permalink
Skip CachedObservableOriginal when no getCacheKey()
Browse files Browse the repository at this point in the history
Don't wrap with overhead if request caching is not being used.
  • Loading branch information
benjchristensen committed May 5, 2014
1 parent 3ba9f78 commit 1bd64e0
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 1bd64e0

Please sign in to comment.