I'm creating a REST-client with a
@Cacheable
method. Since
@Cacheable
is broken for suspend functions, I tried to do this with reactor-types for the specific method instead. Looks something like this:
@Cacheable("my-cache")
fun fetchThing(key: String): Mono<Thing> =
webClient.get("/thing/{key}", key)
.retrieve()
.bodyToMono()
Now, in the code where I use this. I want to bridge back into awesome realm of suspend (π), so I do:
restClient.fetchThing(key).awaitSingle()
. However, it seems that invoking
awaitSingle()
twice on a
Mono
created this way will actually cause the webrequest to fire again, instead of lazily returning the already existing result in the
Mono
.. Does anyone know the proper way to get back to suspend functions after creating a Mono like this? Should I map the mono to a lazy mono of first result or something?