@@ -110,9 +110,13 @@ Optional<CompletableFuture<V>> getIfPresent(K key) {
110110 boolean cachingEnabled = loaderOptions .cachingEnabled ();
111111 if (cachingEnabled ) {
112112 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 ) {
116120 }
117121 }
118122 }
@@ -307,10 +311,14 @@ private void possiblyClearCacheEntriesOnExceptions(List<K> keys) {
307311 private CompletableFuture <V > loadFromCache (K key , Object loadContext , boolean batchingEnabled ) {
308312 final Object cacheKey = loadContext == null ? getCacheKey (key ) : getCacheKeyWithContext (key , loadContext );
309313
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 ) {
314322 }
315323
316324 CompletableFuture <V > loadCallFuture = queueOrInvokeLoader (key , loadContext , batchingEnabled , true );
0 commit comments