Browse Source

EhCacheFactoryBean applies listeners and enabled/disabled flags to existing cache regions as well (SPR-9392)

3.1.x
Juergen Hoeller 14 years ago
parent
commit
dcb44264ad
  1. 35
      org.springframework.context/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java

35
org.springframework.context/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -332,6 +332,21 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -332,6 +332,21 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
this.cacheManager.addCache(rawCache);
}
if (this.cacheEventListeners != null) {
for (CacheEventListener listener : this.cacheEventListeners) {
rawCache.getCacheEventNotificationService().registerListener(listener);
}
}
if (this.statisticsEnabled) {
rawCache.setStatisticsEnabled(true);
}
if (this.sampledStatisticsEnabled) {
rawCache.setSampledStatisticsEnabled(true);
}
if (this.disabled) {
rawCache.setDisabled(true);
}
// Decorate cache if necessary.
Ehcache decoratedCache = decorateCache(rawCache);
if (decoratedCache != rawCache) {
@ -345,7 +360,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -345,7 +360,7 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
*/
protected Cache createCache() {
// Only call EHCache 1.6 constructor if actually necessary (for compatibility with EHCache 1.3+)
Cache cache = (!this.clearOnFlush) ?
return (!this.clearOnFlush) ?
new Cache(this.cacheName, this.maxElementsInMemory, this.memoryStoreEvictionPolicy,
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
@ -355,22 +370,6 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware, @@ -355,22 +370,6 @@ public class EhCacheFactoryBean implements FactoryBean<Ehcache>, BeanNameAware,
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
this.bootstrapCacheLoader, this.maxElementsOnDisk, this.diskSpoolBufferSize);
if (this.cacheEventListeners != null) {
for (CacheEventListener listener : this.cacheEventListeners) {
cache.getCacheEventNotificationService().registerListener(listener);
}
}
if (this.statisticsEnabled) {
cache.setStatisticsEnabled(true);
}
if (this.sampledStatisticsEnabled) {
cache.setSampledStatisticsEnabled(true);
}
if (this.disabled) {
cache.setDisabled(true);
}
return cache;
}
/**

Loading…
Cancel
Save