EhCacheFactoryBean calls CacheManager.addCache before setStatisticsEnabled

Issue: SPR-11080
Issue: SPR-11092
(cherry picked from commit 6ce2eb9)
This commit is contained in:
Juergen Hoeller
2013-12-03 01:30:22 +01:00
parent f5a310ad57
commit 6c1f62b19d

View File

@@ -234,6 +234,7 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
// Fetch cache region: If none with the given name exists, create one on the fly.
Ehcache rawCache;
boolean cacheExists = this.cacheManager.cacheExists(cacheName);
if (cacheExists) {
if (logger.isDebugEnabled()) {
logger.debug("Using existing EhCache cache region '" + cacheName + "'");
@@ -253,6 +254,12 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
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);
}
@@ -263,9 +270,6 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
rawCache.setDisabled(true);
}
if (!cacheExists) {
this.cacheManager.addCache(rawCache);
}
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);