Skip to content

Commit

Permalink
CacheResultInterceptor - use Cache#getAsync() for async return types
Browse files Browse the repository at this point in the history
- deprecate UnresolvedUniValue
  • Loading branch information
mkouba committed Jan 13, 2023
1 parent 42a406c commit ad8e30b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,20 @@ public Object intercept(InvocationContext invocationContext) throws Throwable {
try {
ReturnType returnType = determineReturnType(invocationContext.getMethod().getReturnType());
if (returnType != ReturnType.NonAsync) {
Uni<Object> cacheValue = cache.get(key, new Function<Object, Object>() {
Uni<Object> cacheValue = cache.getAsync(key, new Function<Object, Uni<Object>>() {
@SuppressWarnings("unchecked")
@Override
public Object apply(Object k) {
LOGGER.debugf("Adding %s entry with key [%s] into cache [%s]",
UnresolvedUniValue.class.getSimpleName(), key, binding.cacheName());
return UnresolvedUniValue.INSTANCE;
}
}).onItem().transformToUni(new Function<Object, Uni<?>>() {
@Override
public Uni<?> apply(Object value) {
if (value == UnresolvedUniValue.INSTANCE) {
try {
return asyncInvocationResultToUni(invocationContext.proceed(), returnType)
.call(new Function<Object, Uni<?>>() {
@Override
public Uni<?> apply(Object emittedValue) {
return cache.replaceUniValue(key, emittedValue);
}
});
} catch (CacheException e) {
throw e;
} catch (Exception e) {
throw new CacheException(e);
}
} else {
return Uni.createFrom().item(value);
public Uni<Object> apply(Object key) {
try {
return (Uni<Object>) asyncInvocationResultToUni(invocationContext.proceed(), returnType);
} catch (CacheException e) {
throw e;
} catch (Exception e) {
throw new CacheException(e);
}
}
});

if (binding.lockTimeout() <= 0) {
return createAsyncResult(cacheValue, returnType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
/**
* This value acts as a placeholder in the cache. It will be eventually replaced by the item emitted by the
* {@link io.smallrye.mutiny.Uni Uni} when it has been resolved.
*
* @deprecated This placeholder is not used anymore and will be removed at some time after Quarkus 3.0.
*/
@Deprecated
public class UnresolvedUniValue {

public static final UnresolvedUniValue INSTANCE = new UnresolvedUniValue();
Expand Down

0 comments on commit ad8e30b

Please sign in to comment.