Integration Support with Spring Webflux ? #500
-
Hi , Can we integrate this caffeine library with Spring Webflux (Reactive) ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
Reactor provided this as an add-on, see CacheMono. The JavaDoc shows an example using Caffeine. This design tries to generalize to a
It might be nice if someone wrote an adapter between our async interfaces using |
Beta Was this translation helpful? Give feedback.
-
Hi. I am building a high-performance API service using spring webflux and caffeine.
Finally, I checked if there is a blocking section using reactor/BlockHound (https://github.com/reactor/BlockHound) and it was fine. @ben-manes Although I am careful about the question because I implemented the code using spring f/w, is there any section that could be a problem?? |
Beta Was this translation helpful? Give feedback.
-
I had been struggling with this for a while and didn't find a solution that worked out of the box for me. After some playing around, I got this solution to work. I took the solutions I saw mentioned in various discussion, mainly this one, and created a fully fleshed out solution including imports and the dependencies you need to add to the project, called @AsyncCacheable. Example usage is in the ReadMe. It's @jaesuk-kim0808 's solution, plus a custom annotation and the imports + dependencies. Hopefully somebody finds this useful/it saves you the trouble of trying to implement this 5 times and hitting errors: https://github.com/shaikezr/async-cacheable Also, in the above solution, the cache is only unique by its name. I changed this to be a hash of the params so each cache with different params will be separate and added params for max size and expireAfterWrite. Additionally, I made the key of the cached items include a hash of the method so that methods with the same params get different cache keys. |
Beta Was this translation helpful? Give feedback.
Reactor provided this as an add-on, see CacheMono. The JavaDoc shows an example using Caffeine.
This design tries to generalize to a
Map<K, V>
style cache, which leads to cache stampedes. That has become problematic and they may phase it out (reactor/reactor-addons#237). The proposed replacement follows the strategy that we recommend too,It might be nice if someone wrote an adapter between our async interfaces using
CompletableFuture
to a set usingMono
for convenience of avoiding this wrap/unwrap logic in every use-case. That might…