Browse Source

EhCacheFactoryBean calls CacheManager.addCache before setStatisticsEnabled

Issue: SPR-11080
Issue: SPR-11092
pull/439/head
Juergen Hoeller 12 years ago
parent
commit
6ce2eb9622
  1. 10
      spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java

10
spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java vendored

@ -321,6 +321,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -321,6 +321,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
// create one on the fly.
Ehcache rawCache;
boolean cacheExists = this.cacheManager.cacheExists(this.cacheName);
if (cacheExists) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EhCache cache region '" + this.cacheName + "'");
@ -339,6 +340,12 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -339,6 +340,12 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
rawCache.getCacheEventNotificationService().registerListener(listener);
}
}
// Needs to happen after listener registration but before setStatisticsEnabled
if (!cacheExists) {
this.cacheManager.addCache(rawCache);
}
if (this.statisticsEnabled) {
rawCache.setStatisticsEnabled(true);
}
@ -349,9 +356,6 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -349,9 +356,6 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
rawCache.setDisabled(true);
}
if (!cacheExists) {
this.cacheManager.addCache(rawCache);
}
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);

Loading…
Cancel
Save