【问题标题】:How to enable ehcache statistics on spring xml file如何在 spring xml 文件上启用 ehcache 统计信息
【发布时间】:2011-11-17 19:25:05
【问题描述】:

基于以下配置,我无法在 xml 文件上启用 ehcache 统计信息。没有这样的属性来启用 ehcache 统计。

<bean id="cache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
  <property name="cacheName" value="diskCache"/>
  <property name="cacheManager" ref="cacheManager"/>
  <property name="maxElementsInMemory" value="1"/>
  <property name="overflowToDisk" value="true"/>
  <property name="maxElementsOnDisk" value="10"/>
</bean>

Ehcache 2.4.6 带有禁用的缓存统计信息。

有没有其他人有实现此功能的经验?

对此的任何帮助或想法将不胜感激!

【问题讨论】:

    标签: java spring ehcache


    【解决方案1】:

    看起来内置的EhCacheFactoryBean 不支持设置这个标志(我鼓励你打开一个feature request)。但是,自己添加它相对容易:

    package com.example;
    
    public class EhCacheWithStatisticsFactoryBean extends EhCacheFactoryBean {
    
        private boolean statisticsEnabled;
    
        @Override
        public void afterPropertiesSet() throws CacheException, IOException {
            super.afterPropertiesSet();
            getObject().setStatisticsEnabled(statisticsEnabled);
        }
    
        public void setStatisticsEnabled(boolean statisticsEnabled) {
            this.statisticsEnabled = statisticsEnabled;
        }
    }
    

    及用法:

    <bean id="cache" class="com.example.EhCacheWithStatisticsFactoryBean">
      <property name="cacheName" value="diskCache"/>
      <property name="cacheManager" ref="cacheManager"/>
      <property name="maxElementsInMemory" value="1"/>
      <property name="overflowToDisk" value="true"/>
      <property name="maxElementsOnDisk" value="10"/>
      <property name="statisticsEnabled" value="true"/> <!-- HERE -->
    </bean>
    

    当然,最简单的方法是使用标准的ehcache.xml 文件。

    【讨论】:

    猜你喜欢
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    相关资源
    最近更新 更多