When using the @Cacheable annotation with sync=true parameter, the exceptions are thrown without calling the CacheErrorHandler for underlying cache issues.
**Expected behavior: ** Below code prints "Test Passed" and exit code is 0, logging the connection failure to Redis.
**Actual behavior: ** Below code throws connection exception, never logs the message, and exit code is 1.
@SpringBootApplication
@EnableCaching
public class DemoApplication implements CachingConfigurer {
@Override
public CacheErrorHandler errorHandler() {
return new LoggingCacheErrorHandler(true);
}
@Cacheable(value="test", sync=true)
public String cacheTest(String test) {
return test;
}
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(DemoApplication.class, args);
System.out.println(context.getBean(DemoApplication.class).cacheTest("Test Passed"));
}
}
If we change the sync=true to sync=false then the code works as expected, but when sync=true it fails and never calls the error handler.
Comment From: mhalbritter
Duplicate of https://github.com/spring-projects/spring-framework/issues/21590.