- Notifications
You must be signed in to change notification settings - Fork38.6k
Description
Hi, I have a piece of code in a reactive project that looks something like that (similar code for demo purposes):
@Cacheable(value =RedisCacheNames.CONSTANT,cacheManager ="redisCacheManager")publicMono<String>get(Integerid) {returnMono.just("result") .doOnSuccess(s ->throwException()) }privatevoidthrowException() {thrownewRuntimeException(); }
I have a specific exception, but it basically extends fromRuntimeException
.
I've been debugging a little, and it seems thatCacheAspectSupport
had a piece of code added in commit8974da2 that changedReactiveCachingHandler
from this:
returnadapter.fromPublisher(Mono.fromFuture(cachedFuture).switchIfEmpty(Mono.defer(() -> (Mono)evaluate(null,invoker,method,contexts))).flatMap(v ->evaluate(Mono.justOrEmpty(unwrapCacheValue(v)),invoker,method,contexts)));
to this:
returnadapter.fromPublisher(Mono.fromFuture(cachedFuture).switchIfEmpty(Mono.defer(() -> (Mono)evaluate(null,invoker,method,contexts))).flatMap(v ->evaluate(Mono.justOrEmpty(unwrapCacheValue(v)),invoker,method,contexts)).onErrorResume(RuntimeException.class,ex -> {try {getErrorHandler().handleCacheGetError((RuntimeException)ex,cache,key);returnevaluate(null,invoker,method,contexts);}catch (RuntimeExceptionexception) {returnMono.error(exception);}}));
The thing is, first evaluate call before the method execution sets the contexts.processed to true, and after my method throws the runtime exception, is caught by thisonErrorResume
, which calls evaluate withcacheHit
set tonull
, and
if (contexts.processed) {returncacheHit;}
returnsnull
.
Is this an actual issue or I am missing something?
As of now I've done a couple of extra tests, and it seems that I cannot throw aRuntimeException
. I have two CacheManagers configured in my Spring Boot project, one for Caffeine and the other one for Redis. This only happens when using theRedisCacheManager
as seen above.
I think this might be becauseCaffeineCache
implementation ofCache
returnsnull
when the element is not present whereasRedisCache
implementation returns a cachedFuture.
Thanks in advance for any help provided!