15
15
*/
16
16
package com .netflix .hystrix ;
17
17
18
- import java .util .concurrent .ConcurrentHashMap ;
19
-
20
- import org .slf4j .Logger ;
21
- import org .slf4j .LoggerFactory ;
22
-
23
- import rx .Observable ;
24
-
25
18
import com .netflix .hystrix .strategy .concurrency .HystrixConcurrencyStrategy ;
26
- import com .netflix .hystrix .strategy .concurrency .HystrixRequestContext ;
27
19
import com .netflix .hystrix .strategy .concurrency .HystrixRequestVariableDefault ;
28
20
import com .netflix .hystrix .strategy .concurrency .HystrixRequestVariableHolder ;
29
21
import com .netflix .hystrix .strategy .concurrency .HystrixRequestVariableLifecycle ;
22
+ import org .slf4j .Logger ;
23
+ import org .slf4j .LoggerFactory ;
24
+ import rx .Observable ;
25
+
26
+ import java .util .concurrent .ConcurrentHashMap ;
30
27
31
28
/**
32
29
* Cache that is scoped to the current request as managed by {@link HystrixRequestVariableDefault}.
@@ -101,11 +98,12 @@ private static HystrixRequestCache getInstance(RequestCacheKey rcKey, HystrixCon
101
98
/* package */ <T > Observable <T > get (String cacheKey ) {
102
99
ValueCacheKey key = getRequestCacheKey (cacheKey );
103
100
if (key != null ) {
104
- if (!HystrixRequestContext .isCurrentThreadInitialized ()) {
101
+ ConcurrentHashMap <ValueCacheKey , Observable <?>> cacheInstance = requestVariableForCache .get (concurrencyStrategy );
102
+ if (cacheInstance == null ) {
105
103
throw new IllegalStateException ("Request caching is not available. Maybe you need to initialize the HystrixRequestContext?" );
106
104
}
107
105
/* look for the stored value */
108
- return (Observable <T >) requestVariableForCache . get ( concurrencyStrategy ) .get (key );
106
+ return (Observable <T >) cacheInstance .get (key );
109
107
}
110
108
return null ;
111
109
}
@@ -128,7 +126,11 @@ private static HystrixRequestCache getInstance(RequestCacheKey rcKey, HystrixCon
128
126
ValueCacheKey key = getRequestCacheKey (cacheKey );
129
127
if (key != null ) {
130
128
/* look for the stored value */
131
- Observable <T > alreadySet = (Observable <T >) requestVariableForCache .get (concurrencyStrategy ).putIfAbsent (key , f );
129
+ ConcurrentHashMap <ValueCacheKey , Observable <?>> cacheInstance = requestVariableForCache .get (concurrencyStrategy );
130
+ if (cacheInstance == null ) {
131
+ throw new IllegalStateException ("Request caching is not available. Maybe you need to initialize the HystrixRequestContext?" );
132
+ }
133
+ Observable <T > alreadySet = (Observable <T >) cacheInstance .putIfAbsent (key , f );
132
134
if (alreadySet != null ) {
133
135
// someone beat us so we didn't cache this
134
136
return alreadySet ;
0 commit comments