I have read many java8 completable future tutorials, most of them are basically same. All talking about some basic method "thenAccept"/"thenApply"/thenCombine" to build a pipeline flow.
But when come to a real work problem, I feel hard to organize different completable futures from different Service. For Example:
interface Cache{
CompletableFuture<Bean> getAsync(long id);
CompletableFuture<Boolean> saveAsync(Bean bean);
}
interface DB{
Completable<Bean> getAsync(long id)
}
the service logic is quite simple, get data from Cache, if exist return to our client, if not, get it from DB, if exist save it back to Cache, and return it to our client, if neither exist in DB, return "error" to client.
using synchronize API, it will be quite straight ahead. But when using asyncnorized API, there are "many pipelines", manny conditional break. I can not figure out how to implement this using CompletableFuture API.