@@ -685,21 +685,15 @@ public DataLoader<K, V> clearAll(BiConsumer<Void, Throwable> handler) {
685
685
/**
686
686
* Primes the cache with the given key and value. Note this will only prime the future cache
687
687
* and not the value store. Use {@link ValueCache#set(Object, Object)} if you want
688
- * o prime it with values before use
688
+ * to prime it with values before use
689
689
*
690
690
* @param key the key
691
691
* @param value the value
692
692
*
693
693
* @return the data loader for fluent coding
694
694
*/
695
695
public DataLoader <K , V > prime (K key , V value ) {
696
- Object cacheKey = getCacheKey (key );
697
- synchronized (this ) {
698
- if (!futureCache .containsKey (cacheKey )) {
699
- futureCache .set (cacheKey , CompletableFuture .completedFuture (value ));
700
- }
701
- }
702
- return this ;
696
+ return prime (key , CompletableFuture .completedFuture (value ));
703
697
}
704
698
705
699
/**
@@ -711,9 +705,25 @@ public DataLoader<K, V> prime(K key, V value) {
711
705
* @return the data loader for fluent coding
712
706
*/
713
707
public DataLoader <K , V > prime (K key , Exception error ) {
708
+ return prime (key , CompletableFutureKit .failedFuture (error ));
709
+ }
710
+
711
+ /**
712
+ * Primes the cache with the given key and value. Note this will only prime the future cache
713
+ * and not the value store. Use {@link ValueCache#set(Object, Object)} if you want
714
+ * to prime it with values before use
715
+ *
716
+ * @param key the key
717
+ * @param value the value
718
+ *
719
+ * @return the data loader for fluent coding
720
+ */
721
+ public DataLoader <K , V > prime (K key , CompletableFuture <V > value ) {
714
722
Object cacheKey = getCacheKey (key );
715
- if (!futureCache .containsKey (cacheKey )) {
716
- futureCache .set (cacheKey , CompletableFutureKit .failedFuture (error ));
723
+ synchronized (this ) {
724
+ if (!futureCache .containsKey (cacheKey )) {
725
+ futureCache .set (cacheKey , value );
726
+ }
717
727
}
718
728
return this ;
719
729
}
0 commit comments