<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false"

<ehcache> 
<!--timeToIdleSeconds 当缓存闲置n秒后销毁 --> 
<!--timeToLiveSeconds 当缓存存活n秒后销毁 --> 
<!-- 
缓存配置 
       name:缓存名称。 
       maxElementsInMemory:缓存最大个数。 
       eternal:对象是否永久有效,一但设置了,timeout将不起作用。 
       timeToIdleSeconds:设置对象在失效前的允许闲置时间(单位:秒)。仅当eternal=false对象不是永久有效时使用,可选属性,默认值是0,也就是可闲置时间无穷大。 
       timeToLiveSeconds:设置对象在失效前允许存活时间(单位:秒)。最大时间介于创建时间和失效时间之间。仅当eternal=false对象不是永久有效时使用,默认是0.,也就是对象存活时间无穷大。 
       overflowToDisk:当内存中对象数量达到maxElementsInMemory时,Ehcache将会对象写到磁盘中。 
       diskSpoolBufferSizeMB:这个参数设置DiskStore(磁盘缓存)的缓存区大小。默认是30MB。每个Cache都应该有自己的一个缓冲区。 
       maxElementsOnDisk:硬盘最大缓存个数。 
       diskPersistent:是否缓存虚拟机重启期数据 Whether the disk store persists between restarts of the Virtual Machine. The default value is false. 
       diskExpiryThreadIntervalSeconds:磁盘失效线程运行时间间隔,默认是120秒。 
       memoryStoreEvictionPolicy:当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)。 
clearOnFlush:内存数量最大时是否清除。

<diskStore path="java.io.tmpdir" />
<defaultCache
maxElementsInMemory="500"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="1200"
overflowToDisk="true" />
<cache name="com.Menu" maxElementsInMemory="150" eternal="false" timeToLiveSeconds="36000" timeToIdleSeconds="3600" overflowToDisk="true"/>
</ehcache>

EhcacheUtil工具类使用:

  

 public class EhcacheUtil {  

     private static final String path = "/ehcache.xml";  

     private URL url;  

     private CacheManager manager;  

     private static EhcacheUtil ehCache;  

     private EhcacheUtil(String path) {
url = getClass().getResource(path);
manager = CacheManager.create(url);
} public static EhcacheUtil getInstance() {
if (ehCache== null) {
ehCache= new EhcacheUtil(path);
}
return ehCache;
} public void put(String cacheName, String key, Object value) {
Cache cache = manager.getCache(cacheName);
Element element = new Element(key, value);
cache.put(element);
} public Object get(String cacheName, String key) {
Cache cache = manager.getCache(cacheName);
Element element = cache.get(key);
return element == null ? null : element.getObjectValue();
} public Cache get(String cacheName) {
return manager.getCache(cacheName);
} public void remove(String cacheName, String key) {
Cache cache = manager.getCache(cacheName);
cache.remove(key);
} }

Ehcache配置详解及CacheManager使用的更多相关文章

  1. Hibernate4搭建Log4J日志管理(附Log4j.properties配置详解)

    1.首先加入slf4j的jar包,即slf4j-api-1.6.1.jar 在hibernate官网下载hibernate-release-4.2.2.Final.zip并解压,在hibernate- ...

  2. spring-boot-starter-redis配置详解

    spring-boot-starter-redis配置详解   spring-boot-starter-redis主要是通过配置RedisConnectionFactory中的相关参数去实现连接red ...

  3. Log4j配置详解(转)

    一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使 ...

  4. logback 常用配置详解<appender>

    logback 常用配置详解 <appender> <appender>: <appender>是<configuration>的子节点,是负责写日志的 ...

  5. [转]阿里巴巴数据库连接池 druid配置详解

    一.背景 java程序很大一部分要操作数据库,为了提高性能操作数据库的时候,又不得不使用数据库连接池.数据库连接池有很多选择,c3p.dhcp.proxool等,druid作为一名后起之秀,凭借其出色 ...

  6. libCURL开源库在VS2010环境下编译安装,配置详解

    libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 http://blog.csdn.net/su ...

  7. logback配置详解3<filter>

    logback 常用配置详解(三) <filter> <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NEUTRAL,ACCEPT其中之一.返回DENY ...

  8. logback配置详解2<appender>

    logback 常用配置详解(二) <appender> <appender>: <appender>是<configuration>的子节点,是负责写 ...

  9. log4j.properties配置详解

    1.Loggers Loggers组件在此系统中被分为五个级别:DEBUG.INFO.WARN.ERROR和FATAL.这五个级别是有顺序的,DEBUG < INFO < WARN < ...

随机推荐

  1. 第48节:Java当中的集合框架

    Java当中的集合框架 01 在我们班里有50位同学,就有50位对象. // 简书作者:达叔小生 Student[] stus = new Student[20]; 结果来了一位插班生,该同学因为觉得 ...

  2. 比较empty()与 isset()d的区别

    比较empty()与 isset()的区别 注意:empty()在PHP5.5之前只能检测变量 isset()只能检测变量 两者之间的联系:empty($var) 等价于 !isset($var)|| ...

  3. python通过手机抓取微信公众号

    使用 Fiddler 抓包分析公众号 打开微信随便选择一个公众号,查看公众号的所有历史文章列表 在 Fiddler 上已经能看到有请求进来了,说明公众号的文章走的都是HTTPS协议,这些请求就是微信客 ...

  4. odoo开发笔记 -- div标签代替odoo button写法

    odoo开发笔记 -- div标签代替odoo button写法 并调用自定义js <footer> <div id="confirm_request_cloud_repo ...

  5. 《JQuery技术内幕》读书笔记——自调用匿名函数剖析

    Javascript语言中的自调用匿名函数格式如下: (function(){ //do somethings })(); 它还有另外两种等价写法如下: //等价写法一 (function(){ // ...

  6. 浅谈Mybatis连接原理

    众所周知数据库连接的过程,但是最近面试的人(菜面菜),都说用的SSM框架,但是我问了一下,mybatis是怎么连接上mysql的,基本上都会说:配置好的,直接用了,今天我来抛砖引玉一下,欢迎拍砖! 什 ...

  7. Go基础系列:函数(1)

    Go中函数特性简介 对Go中的函数特性做一个总结.懂则看,不懂则算. Go中有3种函数:普通函数.匿名函数(没有名称的函数).方法(定义在struct上的函数). Go编译时不在乎函数的定义位置,但建 ...

  8. Apollo 7 — ConfigService 消息扫描设计实现

    目录 设计 代码实现 总结 1.设计 Apollo 为了减少依赖,将本来 MQ 的职责转移到了 Mysql 中.具体表现为 Mysql 中的 ReleaseMessage 表. 具体官方文档可见:发送 ...

  9. 一个Fragment的实例

    @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method s ...

  10. 第一册:lesson fifty one.

    原文: A pleasant climate. A:Where do you come frome? B:I come from Greece. A:What's the climate like i ...