-
Notifications
You must be signed in to change notification settings - Fork 88
Description
I recently stumbled upon following issue.
Behaviour of the setCaches in SSMCacheManager differs based on the way we create the manager. If it is annotated as @Bean - everything works as a charm, but if it is simple factory method - we need to use setter to setup the collection and then add each cache separately.
As the code serves as thousands of words, this works:
@Bean
public CacheManager cacheManager() {
return new CompositeCacheManager(
inMemoryCache(),
ssmCacheManager());
}
@Bean
public SSMCacheManager ssmCacheManager() {
SSMCache cache = createCache(CACHE_NAME);
SSMCacheManager ssmCM = new SSMCacheManager();
ssmCM.setCaches(ImmutableList.of(cache))
}
this does not:
@Bean
public CacheManager cacheManager() {
return new CompositeCacheManager(
inMemoryCache(),
ssmCacheManager());
}
private SSMCacheManager ssmCacheManager() {
SSMCache cache = createCache(CACHE_NAME);
SSMCacheManager ssmCM = new SSMCacheManager();
ssmCM.setCaches(ImmutableList.of(cache))
}
the only way to make it working is to call afterPropertiesSet manually or setCaches with new collection and call addCache for each cache separately.
Solution:
- At least a documentation so that one does not have to go through the code
- If the
SSMCacheManageris not created as a bean, maybe some fallback forgetCache? so that ifcacheMapis empty or ifcacheMap.get(name) == nullit would check caches collection for the name? - setter could register caches
Background:
We decided to introduce in-memory cache in front of memcache (aws elasticache to be specific) to cut delays that are caused by network. As a result, we started returning CompositeCacheManager as a CacheManager bean, and method that created SSMCacheManager became a private method (we removed the Bean annotation). We found the hard way, that cache stopped working - it did not find proper cache names. Simple change to addCache also did not help - there was null pointer exception.