Skip to content

Commit

Permalink
Merge pull request #885 from mattrjacobs/single-lookup-of-request-cache
Browse files Browse the repository at this point in the history
Only lookup if the request cache is enabled once per command invocation
  • Loading branch information
mattrjacobs committed Sep 9, 2015
2 parents c6ff67f + 34652b9 commit ace52c6
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ protected static enum TimedOutStatus {
protected final AtomicBoolean isExecutedInThread = new AtomicBoolean(false);
protected final AtomicReference<Action0> endCurrentThreadExecutingCommand = new AtomicReference<Action0>(); // don't like how this is being done


/**
* Instance of RequestCache logic
*/
Expand Down Expand Up @@ -354,8 +353,10 @@ public Observable<R> toObservable() {
throw new IllegalStateException("This instance can only be executed once. Please instantiate a new instance.");
}

final boolean requestCacheEnabled = isRequestCachingEnabled();

/* try from cache first */
if (isRequestCachingEnabled()) {
if (requestCacheEnabled) {
Observable<R> fromCache = requestCache.get(getCacheKey());
if (fromCache != null) {
/* mark that we received this response from cache */
Expand Down Expand Up @@ -475,7 +476,7 @@ public void call() {
});

// put in cache
if (isRequestCachingEnabled()) {
if (requestCacheEnabled) {
// wrap it for caching
o = new CachedObservableOriginal<R>(o.cache(), this);
Observable<R> fromCache = requestCache.putIfAbsent(getCacheKey(), o);
Expand Down

0 comments on commit ace52c6

Please sign in to comment.