Skip to content

Commit 603b963

Browse files
mpiresbbakerman
mpires
authored andcommitted
Locking behavior conditional to caching being enabled (#12)
1 parent aa2994e commit 603b963

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/main/java/org/dataloader/DataLoader.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,12 @@ public CompletableFuture<V> load(K key) {
180180
Object cacheKey = getCacheKey(nonNull(key));
181181
stats.incrementLoadCount();
182182

183-
synchronized (futureCache) {
184-
if (loaderOptions.cachingEnabled() && futureCache.containsKey(cacheKey)) {
185-
stats.incrementCacheHitCount();
186-
return futureCache.get(cacheKey);
183+
if (loaderOptions.cachingEnabled()) {
184+
synchronized (futureCache) {
185+
if (futureCache.containsKey(cacheKey)) {
186+
stats.incrementCacheHitCount();
187+
return futureCache.get(cacheKey);
188+
}
187189
}
188190
}
189191

0 commit comments

Comments
 (0)