Skip to content
Prev Previous commit
name changing to putIfAbsentAtomically
  • Loading branch information
andimarek committed Oct 23, 2025
commit 54197a08cabc80e9f0a95e70c15b5963c56d8a1b
2 changes: 1 addition & 1 deletion src/main/java/org/dataloader/CacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static <K, V> CacheMap<K, V> simpleMap() {
*
* @return the cache map for fluent coding
*/
CompletableFuture<V> setIfAbsent(K key, CompletableFuture<V> value);
CompletableFuture<V> putIfAbsentAtomically(K key, CompletableFuture<V> value);

/**
* Deletes the entry with the specified key from the cache map, if it exists.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/dataloader/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public DataLoader<K, V> prime(K key, Exception error) {
*/
public DataLoader<K, V> prime(K key, CompletableFuture<V> value) {
Object cacheKey = getCacheKey(key);
futureCache.setIfAbsent(cacheKey, value);
futureCache.putIfAbsentAtomically(cacheKey, value);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/dataloader/DataLoaderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ CompletableFuture<V> load(K key, Object loadContext) {
if (batchingEnabled) {
loadCallFuture = new CompletableFuture<>();
if (futureCachingEnabled) {
CompletableFuture<V> cachedFuture = futureCache.setIfAbsent(cacheKey, loadCallFuture);
CompletableFuture<V> cachedFuture = futureCache.putIfAbsentAtomically(cacheKey, loadCallFuture);
if (cachedFuture != null) {
// another thread was faster and created a matching CF ... hence this is really a cachehit and we are done
stats.incrementCacheHitCount(new IncrementCacheHitCountStatisticsContext<>(key, loadContext));
Expand All @@ -183,7 +183,7 @@ CompletableFuture<V> load(K key, Object loadContext) {
// immediate execution of batch function
loadCallFuture = invokeLoaderImmediately(key, loadContext, true);
if (futureCachingEnabled) {
CompletableFuture<V> cachedFuture = futureCache.setIfAbsent(cacheKey, loadCallFuture);
CompletableFuture<V> cachedFuture = futureCache.putIfAbsentAtomically(cacheKey, loadCallFuture);
if (cachedFuture != null) {
// another thread was faster and the loader was invoked twice with the same key
// we are disregarding the resul of our dispatch call and use the already cached value
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/dataloader/impl/DefaultCacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Collection<CompletableFuture<V>> getAll() {
* {@inheritDoc}
*/
@Override
public CompletableFuture<V> setIfAbsent(K key, CompletableFuture<V> value) {
public CompletableFuture<V> putIfAbsentAtomically(K key, CompletableFuture<V> value) {
return cache.putIfAbsent(key, value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/ReadmeExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public Collection<CompletableFuture<Object>> getAll() {
}

@Override
public CompletableFuture<Object> setIfAbsent(Object key, CompletableFuture value) {
public CompletableFuture<Object> putIfAbsentAtomically(Object key, CompletableFuture value) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/dataloader/fixtures/CustomCacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Collection<CompletableFuture<Object>> getAll() {
}

@Override
public CompletableFuture<Object> setIfAbsent(String key, CompletableFuture<Object> value) {
public CompletableFuture<Object> putIfAbsentAtomically(String key, CompletableFuture<Object> value) {
return stash.putIfAbsent(key, value);
}

Expand Down