Using Quarkus cache directly instead of CacheResult #29750
Replies: 4 comments 3 replies
-
/cc @gwenneg |
Beta Was this translation helpful? Give feedback.
-
Hi @sandip-stats. Mixing async calls based on @Inject
Cache cache;
public Uni<Object> getNonBlockingExpensiveValue(Object key) {
return cache.get(key, k -> UnresolvedUniValue.INSTANCE)
.onItem().transformToUni(value -> {
if (value == UnresolvedUniValue.INSTANCE) {
return DBservice.findById(key)
.call(emittedValue -> cache.replaceUniValue(key, emittedValue));
} else {
return Uni.createFrom().item(value);
}
});
}
This isn't really user-friendly so I'm not sure it is a good idea to introduce that into the programmatic API considering that the annotations caching API provides an alternative to achieve the same goal in a much easier way. |
Beta Was this translation helpful? Give feedback.
-
@gwenneg How about to add an interface? TBH, I do not really understand current Thanks |
Beta Was this translation helpful? Give feedback.
-
Hi @jie-huang.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
HI,
This is with reference to 'https://quarkus.io/guides/cache'. I see that the cache can be used directly as also has been mentioned in the blog.
I was wondering if their is a way I can embed a DB call (using reactive style via panache) in a non blocking way, in the placeholder . The code below which works but in a blocking manner is ...
Do note that
DBservice.findById(k)
is returning a Uni using the 'active record pattern'.Any suggestion would be of great help.
Beta Was this translation helpful? Give feedback.
All reactions