Skip to content

Commit

Permalink
Merge pull request #887 from mattrjacobs/single-collapser-request-cac…
Browse files Browse the repository at this point in the history
…he-lookup

In HystrixCollapser, only check if request cache is enabled once
  • Loading branch information
mattrjacobs committed Sep 9, 2015
2 parents ace52c6 + 7bbee32 commit 317eaa9
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,10 @@ public Observable<ResponseType> toObservable() {
*/
public Observable<ResponseType> toObservable(Scheduler observeOn) {

final boolean isRequestCacheEnabled = getProperties().requestCacheEnabled().get();

/* try from cache first */
if (getProperties().requestCacheEnabled().get()) {
if (isRequestCacheEnabled) {
Observable<ResponseType> fromCache = requestCache.get(getCacheKey());
if (fromCache != null) {
metrics.markResponseFromCache();
Expand All @@ -389,7 +391,7 @@ public Observable<ResponseType> toObservable(Scheduler observeOn) {
RequestCollapser<BatchReturnType, ResponseType, RequestArgumentType> requestCollapser = collapserFactory.getRequestCollapser(collapserInstanceWrapper);
Observable<ResponseType> response = requestCollapser.submitRequest(getRequestArgument());
metrics.markRequestBatched();
if (getProperties().requestCacheEnabled().get()) {
if (isRequestCacheEnabled) {
/*
* A race can occur here with multiple threads queuing but only one will be cached.
* This means we can have some duplication of requests in a thread-race but we're okay
Expand Down

0 comments on commit 317eaa9

Please sign in to comment.