Comment From: bclozel

Sorry, but we don't accept PRs without any rationale nor explanation, especially for new features and new API.

If I understand correctly, this change would turn cache entries into CompletableFuture<V>. As outlined in #17559, this is not supported (and it won't be supported by the JRS, see jsr107/jsr107spec#312). If you wish to use this feature, you can use Caffeine directly. We might reconsider this in the future with #17920, but we're missing critical bits right now to work on that.

Also, please run the build locally before submitting a PR - this change is failing the build. Thanks!

Comment From: jizhuozhi

Hello, @bclozel . It's my mistake. I just ran the test but forgot to check the style.

My intention is not to get CompletableFuture to make asynchronous calls, but to be able to use asynchronous API when refreshing the cache (this can avoid executor blocking).

The problem I have encountered is that when using Spring Cloud LoadBalancer (it uses CaffeineCacheManager to cache service instances), I don't want to get the instance from the registry when it expires, but pull the latest content from the registry regularly And replace the content in the cache (Caffeine provides the ability to refresh regularly). Most registry SDKs provide asynchronous APIs to avoid blocking the calling thread, but now CaffeineCacheManager only supports synchronous loading of values, so I have to convert asynchronous to synchronous and block here, which will affect the update of other cache values.

In fact, because com.github.benmanes.caffeine.cache.AsyncLoadingCache#synchronous is used to create a view of cache, for the caller of the cache, it is still synchronously obtaining data, and only the IO that occurs during refresh is affected operation only

Comment From: jhoeller

While this has been declined initially (and cannot be reopened anymore as a pull request), I'm effectively addressing this along with #17920 now. CaffeineCacheManager has a general setAsyncCacheMode(boolean) method now, as well as a setAsyncCacheLoader method which implicitly sets that flag as well. We not only build internally async caches, we also leverage the Caffeine AsyncCache interface for our new CompletableFuture-based retrieve operations now.