ehcache的配置使用
2009-11-12 07:56
190 查看
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect">
updateCheck:是否检测更新,如果设置为true,它会到www.terracotta.org检测是否有新的包
monitoring: determines whether the CacheManager should
automatically register the SampledCacheMBean with the system MBean server.这个只是在使用Terracotta clustering才用到的,不是的话可以设置为off
测试代码
import net.sf.ehcache.CacheManager;
public class Test {
public void test() {
CacheManager manager = CacheManager.create();
net.sf.ehcache.Cache cache = manager.getCache("sampleCache1");
net.sf.ehcache.Element element = cache.get("date");
if(element==null){
element = new net.sf.ehcache.Element("date","aaaaaaaa");
cache.put(element);
//cache.flash();(对于cacahe.flash()下面要单独说明)
System.out.println("新的数据"+element.getValue());
}
else{
System.out.println("旧的数据"+element.getValue());
}
}
}
cacahe.flash() 有些文档说,只有程序显示调用cacahe.flash() ,才会将缓存写入到磁盘,这是错误的认识
其实cacahe.flash()是将内存中的缓存写入到磁盘,并将内存中的缓存清除,程序中并不需要显示的调用,
也就是说如果你设置了maxElementsInMemory的值大于0,同时程序中又显示调用flash(),那么内存中的数据将永远被清除,总是读取新的数据
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true" monitoring="autodetect">
updateCheck:是否检测更新,如果设置为true,它会到www.terracotta.org检测是否有新的包
monitoring: determines whether the CacheManager should
automatically register the SampledCacheMBean with the system MBean server.这个只是在使用Terracotta clustering才用到的,不是的话可以设置为off
测试代码
import net.sf.ehcache.CacheManager;
public class Test {
public void test() {
CacheManager manager = CacheManager.create();
net.sf.ehcache.Cache cache = manager.getCache("sampleCache1");
net.sf.ehcache.Element element = cache.get("date");
if(element==null){
element = new net.sf.ehcache.Element("date","aaaaaaaa");
cache.put(element);
//cache.flash();(对于cacahe.flash()下面要单独说明)
System.out.println("新的数据"+element.getValue());
}
else{
System.out.println("旧的数据"+element.getValue());
}
}
}
cacahe.flash() 有些文档说,只有程序显示调用cacahe.flash() ,才会将缓存写入到磁盘,这是错误的认识
其实cacahe.flash()是将内存中的缓存写入到磁盘,并将内存中的缓存清除,程序中并不需要显示的调用,
也就是说如果你设置了maxElementsInMemory的值大于0,同时程序中又显示调用flash(),那么内存中的数据将永远被清除,总是读取新的数据
相关文章推荐
- Spring-boot使用Ehcache配置
- Hibernate 二级缓存的配置及使用_EhCache
- Spring 使用注解配置使用ehcache
- Ehcache配置详解及CacheManager使用
- Ehcache缓存配置和基本使用
- Ehcache配置详解及CacheManager使用
- Ehcache配置详解及CacheManager使用
- 配置Spring+hibernate使用ehcache作为second-level cache
- Spring Cloud Spring Boot mybatis分布式微服务云架构(三十三)注解配置与EhCache使用(1)
- Spring Boot中的缓存支持(一)注解配置与EhCache使用
- 使用Spring 注解整合 Ehcache 配置
- Ehcache缓存配置和基本使用
- ehcache的配置使用
- Spring Boot中的缓存支持(一)注解配置与EhCache使用
- Ehcache2 的配置(不使用配置文件)
- Ehcache配置详解及CacheManager使用
- ehcache配置:使用Spring+SpringMVC+Mybatis或者有shiro【转】
- 知识积累(十六)——使用spring和hibernate配置ehcache和query cache
- jcs、ehcache的配置及使用
- EHCache概念,配置文件,使用示例