登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

kangzye的博客

加Q群25382780切磋java,加19360923群研究JavaScript

 
 
 

日志

 
 

ehcache配置备忘笔记  

2010-11-04 15:04:17|  分类: ehcache |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
ehcache被hibernate用作默认的缓存工具,想必就是个好东西。配置使用都还蛮简单。
其官网配置说明见:http://ehcache.org/documentation/configuration.html
配置:
<cache
        name="mmsIds"
        maxElementsInMemory="9000000"
        eternal="false"
        overflowToDisk="true"
        timeToIdleSeconds="86400"
        timeToLiveSeconds="86400"
        diskPersistent="true"
        memoryStoreEvictionPolicy="LFU"
    />
这里仅说说diskPersistent,这个如果设置为false,那么你的程序缓存了内容后,如果程序关闭了,那么缓存的东西就丢失了,因为这个如果设置为false,那么就不会持久化到硬盘,如果要下次启动程序还能访问上次的缓存那么就需要设置为true。
使用:
CacheManager manager=null;
Cache cache=null;
try {
    manager=CacheManager.create(new FileInputStream(new File("./ehcache.xml")));
} catch (CacheException e) {
    throw new RuntimeException("EHCache缓存构建失败:"+e.getMessage(),e);
} catch (FileNotFoundException e) {
    throw new RuntimeException("EHCache配置文件未找到:"+e.getMessage(),e);
}
cache = manager.getCache("mmsIds");
String key="zhangshan";
int score=90;
cache.put(new Element(key,score));

//red
int score=Integer.parseInt(cache.get(zhangshan).getValue().toString());
  评论这张
 
阅读(783)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018