@@ -110,9 +110,13 @@ Optional<CompletableFuture<V>> getIfPresent(K key) {
110
110
boolean cachingEnabled = loaderOptions .cachingEnabled ();
111
111
if (cachingEnabled ) {
112
112
Object cacheKey = getCacheKey (nonNull (key ));
113
- if (futureCache .containsKey (cacheKey )) {
114
- stats .incrementCacheHitCount (new IncrementCacheHitCountStatisticsContext <>(key ));
115
- return Optional .of (futureCache .get (cacheKey ));
113
+ try {
114
+ CompletableFuture <V > cacheValue = futureCache .get (cacheKey );
115
+ if (cacheValue != null ) {
116
+ stats .incrementCacheHitCount (new IncrementCacheHitCountStatisticsContext <>(key ));
117
+ return Optional .of (cacheValue );
118
+ }
119
+ } catch (Exception ignored ) {
116
120
}
117
121
}
118
122
}
@@ -307,10 +311,14 @@ private void possiblyClearCacheEntriesOnExceptions(List<K> keys) {
307
311
private CompletableFuture <V > loadFromCache (K key , Object loadContext , boolean batchingEnabled ) {
308
312
final Object cacheKey = loadContext == null ? getCacheKey (key ) : getCacheKeyWithContext (key , loadContext );
309
313
310
- if (futureCache .containsKey (cacheKey )) {
311
- // We already have a promise for this key, no need to check value cache or queue up load
312
- stats .incrementCacheHitCount (new IncrementCacheHitCountStatisticsContext <>(key , loadContext ));
313
- return futureCache .get (cacheKey );
314
+ try {
315
+ CompletableFuture <V > cacheValue = futureCache .get (cacheKey );
316
+ if (cacheValue != null ) {
317
+ // We already have a promise for this key, no need to check value cache or queue up load
318
+ stats .incrementCacheHitCount (new IncrementCacheHitCountStatisticsContext <>(key , loadContext ));
319
+ return cacheValue ;
320
+ }
321
+ } catch (Exception ignored ) {
314
322
}
315
323
316
324
CompletableFuture <V > loadCallFuture = queueOrInvokeLoader (key , loadContext , batchingEnabled , true );
0 commit comments