Skip to content

Commit 08784f3

Browse files
jhoellercbeams
authored andcommitted
Apply cache settings consistently in EhCacheFactoryBean
EhCacheFactoryBean now applies listeners and enabled/disabled flags to existing cache regions as well. Issue: SPR-9392
1 parent 83fa8e1 commit 08784f3

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache;
3232
import net.sf.ehcache.event.CacheEventListener;
3333
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
34-
3534
import org.apache.commons.logging.Log;
3635
import org.apache.commons.logging.LogFactory;
3736

@@ -333,6 +332,21 @@ public void afterPropertiesSet() throws CacheException, IOException {
333332
this.cacheManager.addCache(rawCache);
334333
}
335334

335+
if (this.cacheEventListeners != null) {
336+
for (CacheEventListener listener : this.cacheEventListeners) {
337+
rawCache.getCacheEventNotificationService().registerListener(listener);
338+
}
339+
}
340+
if (this.statisticsEnabled) {
341+
rawCache.setStatisticsEnabled(true);
342+
}
343+
if (this.sampledStatisticsEnabled) {
344+
rawCache.setSampledStatisticsEnabled(true);
345+
}
346+
if (this.disabled) {
347+
rawCache.setDisabled(true);
348+
}
349+
336350
// Decorate cache if necessary.
337351
Ehcache decoratedCache = decorateCache(rawCache);
338352
if (decoratedCache != rawCache) {
@@ -346,7 +360,7 @@ public void afterPropertiesSet() throws CacheException, IOException {
346360
*/
347361
protected Cache createCache() {
348362
// Only call EHCache 1.6 constructor if actually necessary (for compatibility with EHCache 1.3+)
349-
Cache cache = (!this.clearOnFlush) ?
363+
return (!this.clearOnFlush) ?
350364
new Cache(this.cacheName, this.maxElementsInMemory, this.memoryStoreEvictionPolicy,
351365
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
352366
this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
@@ -356,22 +370,6 @@ protected Cache createCache() {
356370
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
357371
this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
358372
this.bootstrapCacheLoader, this.maxElementsOnDisk, this.diskSpoolBufferSize);
359-
360-
if (this.cacheEventListeners != null) {
361-
for (CacheEventListener listener : this.cacheEventListeners) {
362-
cache.getCacheEventNotificationService().registerListener(listener);
363-
}
364-
}
365-
if (this.statisticsEnabled) {
366-
cache.setStatisticsEnabled(true);
367-
}
368-
if (this.sampledStatisticsEnabled) {
369-
cache.setSampledStatisticsEnabled(true);
370-
}
371-
if (this.disabled) {
372-
cache.setDisabled(true);
373-
}
374-
return cache;
375373
}
376374

377375
/**

0 commit comments

Comments
 (0)