File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
spring-context/src/main/java/org/springframework/cache
spring-context-support/src
main/java/org/springframework/cache/caffeine
test/java/org/springframework/cache/caffeine Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,14 @@ public CompletableFuture<?> retrieve(Object key) {
148
148
@ SuppressWarnings ("unchecked" )
149
149
@ Override
150
150
public <T > CompletableFuture <T > retrieve (Object key , Supplier <CompletableFuture <T >> valueLoader ) {
151
- return (CompletableFuture <T >) getAsyncCache ().get (key , (k , e ) -> valueLoader .get ());
151
+ if (isAllowNullValues ()) {
152
+ return (CompletableFuture <T >) getAsyncCache ()
153
+ .get (key , (k , e ) -> valueLoader .get ().thenApply (this ::toStoreValue ))
154
+ .thenApply (this ::fromStoreValue );
155
+ }
156
+ else {
157
+ return (CompletableFuture <T >) getAsyncCache ().get (key , (k , e ) -> valueLoader .get ());
158
+ }
152
159
}
153
160
154
161
@ Override
Original file line number Diff line number Diff line change @@ -181,7 +181,9 @@ void asyncMode() {
181
181
assertThat (cache1 .retrieve ("key3" , () -> CompletableFuture .completedFuture ("value3" )).join ())
182
182
.isEqualTo ("value3" );
183
183
cache1 .evict ("key3" );
184
+ assertThat (cache1 .retrieve ("key3" )).isNull ();
184
185
assertThat (cache1 .retrieve ("key3" , () -> CompletableFuture .completedFuture (null )).join ()).isNull ();
186
+ assertThat (cache1 .retrieve ("key3" ).join ()).isEqualTo (new SimpleValueWrapper (null ));
185
187
assertThat (cache1 .retrieve ("key3" , () -> CompletableFuture .completedFuture (null )).join ()).isNull ();
186
188
}
187
189
Original file line number Diff line number Diff line change @@ -151,10 +151,10 @@ default CompletableFuture<?> retrieve(Object key) {
151
151
* <p>If possible, implementations should ensure that the loading operation
152
152
* is synchronized so that the specified {@code valueLoader} is only called
153
153
* once in case of concurrent access on the same key.
154
- * <p>Null values are generally not supported by this method. The provided
155
- * {@link CompletableFuture} handle produces a value or raises an exception.
156
- * If the {@code valueLoader} raises an exception, it will be propagated
157
- * to the {@code CompletableFuture} handle returned from here .
154
+ * <p>Null values always indicate a user-level {@code null} value with this
155
+ * method. The provided {@link CompletableFuture} handle produces a value
156
+ * or raises an exception. If the {@code valueLoader} raises an exception,
157
+ * it will be propagated to the returned {@code CompletableFuture} handle.
158
158
* @param key the key whose associated value is to be returned
159
159
* @return the value to which this cache maps the specified key, contained
160
160
* within a {@link CompletableFuture} which will never be {@code null}.
You can’t perform that action at this time.
0 commit comments