Open AndreasPetersen opened 1 year ago
/cc @Ladicek (fault-tolerance), @gwenneg (cache)
The priority of the fault tolerance interceptor (which is what handles @Fallback
) is Interceptor.Priority.PLATFORM_AFTER + 10
by specification.
The priority of the @CacheResult
interceptor is Interceptor.Priority.PLATFORM_BEFORE + 2
.
That is, the caching interceptor runs first. If the caching interceptor itself does some network interactions (talking to Redis in this case), that cannot be guarded by fault tolerance. It is only when the caching interceptor finds that it doesn't have a cached value and attempts to compute it that fault tolerance may come to play. The caching interceptor in such case attempts to call the method (through InvocationContext.proceed()
), and that call goes through the fault tolerance interceptor. When that call returns, either with the return value of the method or with the fallback value, that result will be cached.
That might not be "as expected", but it is certainly "as designed".
Splitting the method into two, as you found, is a good way to make sure the interceptors are applied in the order you desire.
If it works as designed, can we make a better design? I have to split the code into three methods, in order to achieve the desired fallback. This is a lot of boilerplate to add to all our cached methods.
And just to be sure: I'm no expert on the caching extensions, so I can't comment on the other proposals. Throwing a dedicated exception in case of remote cache failure certainly sounds like a good idea, though.
2.
definitely makes a lot of sense. What exceptions are currently thrown?
I think it just throws whatever caused an error. For example when Redis is not available, a ConnectException
is thrown.
Description
This is probably mostly relevent for the Redis backend for Quarkus Cache.
Consider the following:
using Quarkus 3.2.0,
quarkus-redis-cache
andquarkus-smallrye-fault-tolerance
.First I make a call to
hello()
thus populating the cache. When I then close Redis, to simulate a failure to get values from the cache, and callhello()
, I get the following exception:The
@Fallback
annotation does not work in combination with@CacheResult
. Instead, I have to wrap my cached method in order to achieve fallback fault tolerance:I see a number of issues:
@Fallback
does not work as expected in combination with@CacheResult
expensive()
when Redis is closed is too generic: ACompletionException
with a root cause ofConnectException
. If the code inside the cached method could also throw aConnectException
, then it is not possible to define a@Fallback
that only applies for the case where the cache itself fails.I would like to request:
@Fallback
should work in combination with@CacheResult
CacheFailure
exception@Fallback
and not providing afallbackMethod
? I'm not sure how this would follow the Fault Tolerance spec. Alternatively, add an option to@CacheResult(fallback=true)
that would execute the code inside the cached method, in case of a cache retrieval failure.Implementation ideas
No response