惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
C
Check Point Blog
雷峰网
雷峰网
小众软件
小众软件
GbyAI
GbyAI
美团技术团队
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
WordPress大学
WordPress大学
MyScale Blog
MyScale Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
Apple Machine Learning Research
Apple Machine Learning Research
Y
Y Combinator Blog
Jina AI
Jina AI
爱范儿
爱范儿
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美

博客园 - MonkChen

使用阿里云Java SDK 实现 DDNS Tesseract训练 Postgresql Jsonb字段内含数组属性的删除元素操作 Activiti开启SQL Log Drools mvel方言drl断点调试方法 Openfire 编译插件 mysql数据备份 Silverlight 缓存控制策略 Silverlight ComboBox with TreeView silverlight5 net.tcpBinding 跨域策略的解决 WCF CustomBinding 身份验证 CMF Android !No Launcher activity found错误 Android SDK Manager 无法获取列表的解决 Silverlight跨域调用gSoap/Java web service 以及wsdl文件的修改 gSOAP契约函数返回结构体(返回多个值) java jax-ws发布含有DateTime字段的实体的webservice gSoap中文乱码解决 RTMP协议
Ehcache3.4 XML配置硬盘存储
MonkChen · 2017-08-30 · via 博客园 - MonkChen

  最近开始学习使用Ehcache, 3.4的文档实在过于简单,尤其是对于XML配置,例子太少。相对于硬编码,我更偏爱灵活的XML配置,为了实现xml配置,摸索了两天,终于运行成功。

ehcache.xml文件:

<config
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns='http://www.ehcache.org/v3'
    xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core.xsd">
  <persistence directory="d:\\mycache"/>
  
  <cache alias="foo">   
    <key-type>java.lang.String</key-type> 
    <value-type>java.lang.String</value-type> 
    <heap unit="entries">200</heap>
    
  </cache>

  <cache-template name="securityObjTemplate"> 
    <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>   
    <resources>
      <heap unit="entries">2000</heap> 
      <offheap unit="MB">500</offheap>       
      <disk persistent="true" unit="MB">1000</disk>
    </resources>
  </cache-template>
  <!-- 缓存行情数据 -->
  <cache alias="hq_quote11" uses-template="securityObjTemplate">   
       <key-type>java.lang.String</key-type>
    <value-type>java.lang.String</value-type>
  </cache>
  
  <cache alias="last_hq_quote" uses-template="securityObjTemplate">   
  </cache>

</config>

java代码如下:

CacheConfigurationBuilder<String, String> securityConfigBuilder = 
                    xmlConfiguration.newCacheConfigurationBuilderFromTemplate("securityObjTemplate", String.class, String.class); 
            CacheManagerBuilder<CacheManager> cmb = CacheManagerBuilder.newCacheManagerBuilder();
            for(ServiceCreationConfiguration<?> scc:  xmlConfiguration.getServiceCreationConfigurations()) {        
                if(scc instanceof CacheManagerConfiguration) {
                    cmb = cmb.with((CacheManagerConfiguration)scc);
                }
            }
        CacheManager securityCacheManager = cmb.build(true);

Cache cache = securityCacheManager.createCache(key, securityConfigBuilder);