diff --git a/src/main/java/org/dataloader/DataLoaderHelper.java b/src/main/java/org/dataloader/DataLoaderHelper.java index f2437be..b665ada 100644 --- a/src/main/java/org/dataloader/DataLoaderHelper.java +++ b/src/main/java/org/dataloader/DataLoaderHelper.java @@ -73,9 +73,9 @@ Object getCallContext() { Optional> getIfPresent(K key) { synchronized (dataLoader) { - Object cacheKey = getCacheKey(nonNull(key)); boolean cachingEnabled = loaderOptions.cachingEnabled(); if (cachingEnabled) { + Object cacheKey = getCacheKey(nonNull(key)); if (futureCache.containsKey(cacheKey)) { stats.incrementCacheHitCount(); return Optional.of(futureCache.get(cacheKey)); @@ -101,12 +101,12 @@ Optional> getIfCompleted(K key) { CompletableFuture load(K key, Object loadContext) { synchronized (dataLoader) { - Object cacheKey = getCacheKey(nonNull(key)); - stats.incrementLoadCount(); - boolean batchingEnabled = loaderOptions.batchingEnabled(); boolean cachingEnabled = loaderOptions.cachingEnabled(); + Object cacheKey = cachingEnabled ? getCacheKey(nonNull(key)) : null; + stats.incrementLoadCount(); + if (cachingEnabled) { if (futureCache.containsKey(cacheKey)) { stats.incrementCacheHitCount();