In my app I have two dependencies, A and B. Dependency A is a library of mine, but dependency B is not.
Both dependencies make use of Caffeine to cache the results in memory.
This is the configuration for Dependency A (mine):
@Configuration
@EnableCaching
public class CaffeineConfiguration {
@Bean(name="myCacheManager")
public CacheManager cacheManager() {
CaffeineCacheManager cacheManager = new CaffeineCacheManager("user");
cacheManager.setCaffeine(caffeineConfig());
return cacheManager;
}
@Bean(name = "myCaffeineConfig")
public Caffeine caffeineConfig() {
return Caffeine.newBuilder()
.expireAfterAccess(5, TimeUnit.MINUTES);
}
}
When I run my app and make a request that calls the method annotated with @Cacheable, the following Exception is thrown:
java.lang.IllegalArgumentException: Cannot find cache named 'security.remotePublicKeyCache' for Builder[public java.security.PublicKey com.my.dependencyB.MyClass.getCacheableResult(java.lang.String) throws com.my.dependencyB.CannotProvideKeyException] caches=[security.remotePublicKeyCache] | key='' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'
What can I do to avoid having this conflict of Caches?
Thanks
EDIT: I've seen this article from Baeldung https://www.baeldung.com/spring-multiple-cache-managers where he proposes 3 different solutions but the problem I have is with dependencies, not directly in my code and I'm not sure if I can configure that from my side.