Spring caching does not currently work as I would expect for methods that return a Mono type. I suggest an enhancement to support the caching of the value emitted from the mono as opposed to the mono itself.

E.g.

@Cacheable(...) public Mono<> expensiveOperation(...)

It should work in the same way as for any other cacheable except targeting the emitted value rather than the actual mono. In particular it should support custom keys, cache managers, etc.

We have a rough implementation that we are using at Booking.com. I’d be happy to contribute to this if it is accepted.

Comment From: pstitt

Btw, I have searched stack overflow. Although there are alternative solutions such as reactor’s CacheMono, these require more code and are not as natural for people already familiar with spring caching.

Comment From: bclozel

Closing as a duplicate of #17920. Feel free to comment that issue.

Thanks!