Synchronized cache creation on CacheManager
Issue: SPR-11132
(cherry picked from commit de890fd)
This commit is contained in:
parent
c1b772cd9c
commit
1dc79f7f9c
|
|
@ -316,46 +316,48 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
|
||||||
this.cacheName = this.beanName;
|
this.cacheName = this.beanName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch cache region: If none with the given name exists,
|
synchronized (this.cacheManager) {
|
||||||
// create one on the fly.
|
// Fetch cache region: If none with the given name exists,
|
||||||
Ehcache rawCache;
|
// create one on the fly.
|
||||||
boolean cacheExists = this.cacheManager.cacheExists(cacheName);
|
Ehcache rawCache;
|
||||||
if (cacheExists) {
|
boolean cacheExists = this.cacheManager.cacheExists(this.cacheName);
|
||||||
if (logger.isDebugEnabled()) {
|
if (cacheExists) {
|
||||||
logger.debug("Using existing EhCache cache region '" + this.cacheName + "'");
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Using existing EhCache cache region '" + this.cacheName + "'");
|
||||||
|
}
|
||||||
|
rawCache = this.cacheManager.getEhcache(this.cacheName);
|
||||||
}
|
}
|
||||||
rawCache = this.cacheManager.getEhcache(this.cacheName);
|
else {
|
||||||
}
|
if (logger.isDebugEnabled()) {
|
||||||
else {
|
logger.debug("Creating new EhCache cache region '" + this.cacheName + "'");
|
||||||
if (logger.isDebugEnabled()) {
|
}
|
||||||
logger.debug("Creating new EhCache cache region '" + this.cacheName + "'");
|
rawCache = createCache();
|
||||||
}
|
}
|
||||||
rawCache = createCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.cacheEventListeners != null) {
|
if (this.cacheEventListeners != null) {
|
||||||
for (CacheEventListener listener : this.cacheEventListeners) {
|
for (CacheEventListener listener : this.cacheEventListeners) {
|
||||||
rawCache.getCacheEventNotificationService().registerListener(listener);
|
rawCache.getCacheEventNotificationService().registerListener(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.statisticsEnabled) {
|
||||||
|
rawCache.setStatisticsEnabled(true);
|
||||||
|
}
|
||||||
|
if (this.sampledStatisticsEnabled) {
|
||||||
|
rawCache.setSampledStatisticsEnabled(true);
|
||||||
|
}
|
||||||
|
if (this.disabled) {
|
||||||
|
rawCache.setDisabled(true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (this.statisticsEnabled) {
|
|
||||||
rawCache.setStatisticsEnabled(true);
|
|
||||||
}
|
|
||||||
if (this.sampledStatisticsEnabled) {
|
|
||||||
rawCache.setSampledStatisticsEnabled(true);
|
|
||||||
}
|
|
||||||
if (this.disabled) {
|
|
||||||
rawCache.setDisabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cacheExists) {
|
if (!cacheExists) {
|
||||||
this.cacheManager.addCache(rawCache);
|
this.cacheManager.addCache(rawCache);
|
||||||
|
}
|
||||||
|
Ehcache decoratedCache = decorateCache(rawCache);
|
||||||
|
if (decoratedCache != rawCache) {
|
||||||
|
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
|
||||||
|
}
|
||||||
|
this.cache = decoratedCache;
|
||||||
}
|
}
|
||||||
Ehcache decoratedCache = decorateCache(rawCache);
|
|
||||||
if (decoratedCache != rawCache) {
|
|
||||||
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
|
|
||||||
}
|
|
||||||
this.cache = decoratedCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue