Skip to content

Commit

Permalink
EhCacheFactoryBean does not call set(Sampled)StatisticsEnabled on EhC…
Browse files Browse the repository at this point in the history
…ache 2.7/2.8

Issue: SPR-11265
  • Loading branch information
jhoeller committed Dec 30, 2013
1 parent 0657136 commit 73d8f06
Showing 1 changed file with 20 additions and 7 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.ClassUtils;

/**
* {@link FactoryBean} that creates a named EhCache {@link net.sf.ehcache.Cache} instance
Expand All @@ -63,6 +64,11 @@
*/
public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBean<Ehcache>, BeanNameAware, InitializingBean {

// EhCache's setStatisticsEnabled(boolean) available? Not anymore as of EhCache 2.7...
private static final boolean setStatisticsAvailable =
ClassUtils.hasMethod(Ehcache.class, "setStatisticsEnabled", boolean.class);


protected final Log logger = LogFactory.getLog(getClass());

private CacheManager cacheManager;
Expand Down Expand Up @@ -188,15 +194,19 @@ public void setCacheEventListeners(Set<CacheEventListener> cacheEventListeners)

/**
* Set whether to enable EhCache statistics on this cache.
* @see net.sf.ehcache.Cache#setStatisticsEnabled
* <p>Note: As of EhCache 2.7, statistics are enabled by default, and cannot be turned off.
* This setter therefore has no effect in such a scenario.
* @see net.sf.ehcache.Ehcache#setStatisticsEnabled
*/
public void setStatisticsEnabled(boolean statisticsEnabled) {
this.statisticsEnabled = statisticsEnabled;
}

/**
* Set whether to enable EhCache's sampled statistics on this cache.
* @see net.sf.ehcache.Cache#setSampledStatisticsEnabled
* <p>Note: As of EhCache 2.7, statistics are enabled by default, and cannot be turned off.
* This setter therefore has no effect in such a scenario.
* @see net.sf.ehcache.Ehcache#setSampledStatisticsEnabled
*/
public void setSampledStatisticsEnabled(boolean sampledStatisticsEnabled) {
this.sampledStatisticsEnabled = sampledStatisticsEnabled;
Expand Down Expand Up @@ -263,11 +273,14 @@ public void afterPropertiesSet() throws CacheException, IOException {
this.cacheManager.addCache(rawCache);
}

if (this.statisticsEnabled) {
rawCache.setStatisticsEnabled(true);
}
if (this.sampledStatisticsEnabled) {
rawCache.setSampledStatisticsEnabled(true);
// Only necessary on EhCache <2.7: As of 2.7, statistics are on by default.
if (setStatisticsAvailable) {
if (this.statisticsEnabled) {
rawCache.setStatisticsEnabled(true);
}
if (this.sampledStatisticsEnabled) {
rawCache.setSampledStatisticsEnabled(true);
}
}
if (this.disabled) {
rawCache.setDisabled(true);
Expand Down

0 comments on commit 73d8f06

Please sign in to comment.