Skip to content

Commit dcb4426

Browse files
committed
EhCacheFactoryBean applies listeners and enabled/disabled flags to existing cache regions as well (SPR-9392)
1 parent 9fcb578 commit dcb4426

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -332,6 +332,21 @@ public void afterPropertiesSet() throws CacheException, IOException {
332332
this.cacheManager.addCache(rawCache);
333333
}
334334

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+
335350
// Decorate cache if necessary.
336351
Ehcache decoratedCache = decorateCache(rawCache);
337352
if (decoratedCache != rawCache) {
@@ -345,7 +360,7 @@ public void afterPropertiesSet() throws CacheException, IOException {
345360
*/
346361
protected Cache createCache() {
347362
// Only call EHCache 1.6 constructor if actually necessary (for compatibility with EHCache 1.3+)
348-
Cache cache = (!this.clearOnFlush) ?
363+
return (!this.clearOnFlush) ?
349364
new Cache(this.cacheName, this.maxElementsInMemory, this.memoryStoreEvictionPolicy,
350365
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
351366
this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
@@ -355,22 +370,6 @@ protected Cache createCache() {
355370
this.overflowToDisk, null, this.eternal, this.timeToLive, this.timeToIdle,
356371
this.diskPersistent, this.diskExpiryThreadIntervalSeconds, null,
357372
this.bootstrapCacheLoader, this.maxElementsOnDisk, this.diskSpoolBufferSize);
358-
359-
if (this.cacheEventListeners != null) {
360-
for (CacheEventListener listener : this.cacheEventListeners) {
361-
cache.getCacheEventNotificationService().registerListener(listener);
362-
}
363-
}
364-
if (this.statisticsEnabled) {
365-
cache.setStatisticsEnabled(true);
366-
}
367-
if (this.sampledStatisticsEnabled) {
368-
cache.setSampledStatisticsEnabled(true);
369-
}
370-
if (this.disabled) {
371-
cache.setDisabled(true);
372-
}
373-
return cache;
374373
}
375374

376375
/**

0 commit comments

Comments
 (0)