- 浏览: 299062 次
文章分类
最新评论
-
流年末年:
那四个参数还是没看懂.....能不能解释下showPassst ...
我写的密码强度验证方法(原创) -
kingcs2008:
// 验证pws.jsshowPassstrength(&qu ...
我写的密码强度验证方法(原创) -
h957355152:
请问博主这个怎么用呢?我直接放到jsp里面调用showPass ...
我写的密码强度验证方法(原创) -
qq_15138059:
我写的全国省市县三级联动菜单,拿出来和大家分享了(原创) -
valenon:
评论呢?从MAIL FROM命令开始貌似就出错了:500 Er ...
如何发送伪造的电子邮件
EHCache 是一个纯java的,在Hibernate2.1充当可插入的的在进程中的缓存,它具有以下缓存,最小的依赖性,全面的文特性:快速,简单,丰富的文档和测试用例。
官方网站 http://ehcache.sourceforge.net/
ehcache-1.2 cacheNames 列表的取得;
方法一:
- CacheManager.create();
- String[] cacheNames = CacheManager.getInstance().getCacheNames();
方法二:
- CacheManager manager = new CacheManager();
- String[] cacheNames = manager.getCacheNames();
方法三:
- CacheManager manager1 = new CacheManager( 'src/config/ehcache1.' );
- CacheManager manager2 = new CacheManager( 'src/config/ehcache2.xml' );
- String[] cacheNamesForManager1 = manager1.getCacheNames();
- String[] cacheNamesForManager2 = manager2.getCacheNames();
ehcache-1.2 管理器各种建立的方法:
方法一:
- CacheManager manager = new CacheManager();
方法二:
- CacheManager manager = new CacheManager( 'src/config/ehcache.xml' );
方法三:
- URL url = getClass().getResource( '/anotherconfigurationname.xml' );
- CacheManager manager = new CacheManager(url);
方法四:
- InputStream fis = new FileInputStream( new File( 'src/config/ehcache.xml' ).getAbsolutePath());
- try {
- CacheManager manager = new CacheManager(fis);
- } finally {
- fis.close();
- }
添加和删除缓存元素
设置一个名为test 的新cache,test属性为默认
- CacheManager singletonManager = CacheManager.create();
- singletonManager.addCache( 'testCache' );
- Cache test = singletonManager.getCache( 'testCache' );
设置一个名为test 的新cache,并定义其属性
- CacheManager singletonManager = CacheManager.create();
- Cache memoryOnlyCache = new Cache( 'testCache' , 5000 , false , false , 5 , 2 );
- manager.addCache(memoryOnlyCache);
- Cache test = singletonManager.getCache( 'testCache' );
Cache 属性说明:
构造函数:
public Cache(java.lang.String name,
int maxElementsInMemory,
boolean overflowToDisk,
boolean eternal,
long timeToLiveSeconds,
long timeToIdleSeconds)
参数说明:
name - 元素名字。
maxElementsInMemory - 设定内存中创建对象的最大值。
overflowToDisk - 设置当内存中缓存达到 maxInMemory 限制时元素是否可写到磁盘
上。
eternal - 设置元素(译注:内存中对象)是否永久驻留。如果是,将忽略超
时限制且元素永不消亡。
timeToIdleSeconds - 设置某个元素消亡前的停顿时间。
也就是在一个元素消亡之前,两次访问时间的最大时间间隔值。
这只能在元素不是永久驻留时有效(译注:如果对象永恒不灭,则
设置该属性也无用)。
如果该值是 0 就意味着元素可以停顿无穷长的时间。
timeToLiveSeconds - 为元素设置消亡前的生存时间。
也就是一个元素从构建到消亡的最大时间间隔值。
这只能在元素不是永久驻留时有效。
删除缓存元素:
- CacheManager singletonManager = CacheManager.create();
- singletonManager.removeCache( 'test' );
关闭缓存管理器 CacheManager
- CacheManager.getInstance().shutdown();
对于缓存对象的操作:
放入一个简单的对象到缓存元素;
- Cache cache = manager.getCache( 'sampleCache1' );
- Element element = new Element( 'key1' , 'value1' );
- cache.put(element);
得到一个序列化后的对象属性值;
- Cache cache = manager.getCache( 'sampleCache1' );
- Element element = cache.get( 'key1' );
- Serializable value = element.getValue();
得到一个没有序列化后的对象属性值;
- Cache cache = manager.getCache( 'sampleCache1' );
- Element element = cache.get( 'key1' );
- Object value = element.getObjectValue();
删除一个对象从元素;
- Cache cache = manager.getCache( 'sampleCache1' );
- Element element = new Element( 'key1' , 'value1'
- cache.remove( 'key1' );
对于永固性磁盘存储,立即存储到磁盘:
- Cache cache = manager.getCache( 'sampleCache1' );
- cache.flush();
获得缓存大小:
得到缓存的对象数量;
- Cache cache = manager.getCache( 'sampleCache1' );
- int elementsInMemory = cache.getSize();
得到缓存对象占用内存的数量
- Cache cache = manager.getCache( 'sampleCache1' );
- long elementsInMemory = cache.getMemoryStoreSize();
得到缓存对对象占用磁盘的数量
- Cache cache = manager.getCache( 'sampleCache1' );
- long elementsInMemory = cache.getDiskStoreSize();
关于缓存的读取和丢失的记录
得到缓存读取的命中次数;
- Cache cache = manager.getCache( 'sampleCache1' );
- int hits = cache.getHitCount();
得到内存中缓存读取的命中次数;
- Cache cache = manager.getCache( 'sampleCache1' );
- int hits = cache.getMemoryStoreHitCount();
得到磁盘中缓存读取的命中次数;
- Cache cache = manager.getCache( 'sampleCache1' );
- int hits = cache.getDiskStoreCount();
得到缓存读取的丢失次数;
- Cache cache = manager.getCache( 'sampleCache1' );
- int hits = cache.getMissCountNotFound();
得到缓存读取的已经被销毁的对象丢失次数;
- Cache cache = manager.getCache( 'sampleCache1' );
- int hits = cache.getMissCountExpired();
--------------------------
----------简单例子------------
--------------------------
实战:
XML文件格式:
- maxElementsInMemory = '10000'
- eternal = 'false'
- timeToIdleSeconds = '120'
- timeToLiveSeconds = '120'
- overflowToDisk = 'true'
- diskPersistent = 'false'
- diskExpiryThreadIntervalSeconds = '120'
- memoryStoreEvictionPolicy = 'LRU'
- />
- maxElementsInMemory = '10000'
- eternal = 'false'
- overflowToDisk = 'true'
- timeToIdleSeconds = '2'
- timeToLiveSeconds = '3'
- memoryStoreEvictionPolicy = 'LFU'
- />
源码:
- import java.io.Serializable;
- import net.sf.ehcache.Cache;
- import net.sf.ehcache.CacheManager;
- import net.sf.ehcache.Element;
- /**
- #############################################################################
- # DESCRIBE ehcache 缓存操作DEMO
- # AUTHOR 悠~游
- # DATE 2006-7-10
- # COMPANY FLX
- # PORJECT ehcache-demo
- #############################################################################
- */
- public class Demo {
- static CacheManager manager= new CacheManager();
- /**
- *##############################################################################
- *
- * @DESCRIBE
- * @param args
- * @throws InterruptedException
- *
- *##############################################################################
- */
- public static void main(String[] args) throws InterruptedException {
- String[] cacheNames = manager.getCacheNames();
- System.out.println( '读取的缓存列表为:' );
- for ( int i= 0 ;i System.out.println( '-- ' +(i+ 1 )+ ' ' +cacheNames[i]);
- }
- Cache cache = manager.getCache( 'cache1' );
- Element element = new Element( 'key1' , 'value1' );
- cache.put(element);
- element = cache.get( 'key1' );
- Serializable value = element.getValue();
- System.out.println( '序列化后的值为:' +value.toString());
- element = cache.get( 'key1' );
- Object value1 = element.getObjectValue();
- System.out.println( '未序列化的值为:' +value1.toString());
- int elementsInMemory = cache.getSize();
- System.out.println( '得到缓存的对象数量:' +elementsInMemory);
- long elementsInMemory1 = cache.getMemoryStoreSize();
- System.out.println( '得到缓存对象占用内存的数量:' +elementsInMemory1);
- long elementsInMemory2 = cache.getDiskStoreSize();
- System.out.println( '得到缓存对对象占用磁盘的数量:' +elementsInMemory2);
- int hits = cache.getHitCount();
- System.out.println( '得到缓存读取的命中次数:' +hits);
- int hits1 = cache.getMemoryStoreHitCount();
- System.out.println( '得到内存中缓存读取的命中次数:' +hits1);
- int hits2 =cache.getDiskStoreHitCount();
- System.out.println( '得到磁盘中缓存读取的命中次数:' +hits2);
- int hits3 = cache.getMissCountNotFound();
- System.out.println( '得到缓存读取的丢失次数:' +hits3);
- int hits4 = cache.getMissCountExpired();
- System.out.println( '得到缓存读取的已经被销毁的对象丢失次数:' +hits4);
-
}
发表评论
-
java正则表达式高级用法:转换驼峰标示
2012-06-26 16:47 5745String source = "LastLog ... -
你会做Web上的用户登录功能吗?(转)
2012-06-25 13:22 1319Web上的用户登录功能应 ... -
使用pager-taglib.jar实现的分页技术
2012-06-24 02:34 868//1.导入pager-taglib.jar包; / ... -
我写的验证码生成方案,可防止绝大多数机械识别。
2012-06-20 14:59 2354web.xml <!DOCTYPE web-app ... -
如何在myeclipse中使用maven?
2012-06-11 14:22 168001.下载maven,解压到D盘ma ... -
安装subclipse, MyEclipse8 SVN插件
2012-06-09 22:39 901安装subclipse, MyEclipse8 SVN插件 ... -
PDF生成器
2012-05-28 02:53 815我自己写的一个pdf生成器,能导出百度博客为PDF -
我的自动投票器
2012-04-17 13:58 1262自动投票器,支持windows的32位机器 下面的压缩包是编 ... -
list,set,map,数组间的相互转换(转载)
2012-03-16 16:29 28181.list转set Java代码 ... -
一个给pojo生成hashcode、equals、toString等方法的工具类
2012-03-06 09:52 4218一个给pojo生成hashcode、equals、toStri ... -
ehcache的用法
2012-02-13 22:13 0Spring ... -
使用ehcache来缓存页面
2012-02-13 22:08 764关于缓存的话题,在坛子里已经有很多讨论,简单的来说,如果一个应 ... -
java笔记:自己动手写javaEE框架(二)--业务层Service以及Service单元测试
2012-02-13 00:55 0前一篇博文里有三 ... -
struts+spring+hibernate的web应用<四> Web层代码编写(2)
2012-02-13 00:50 0接着就是写资源文件了。 在 com.game. ... -
struts+spring+hibernate的web应用<四> Web层代码编写(1)
2012-02-13 00:49 1003前面的文章: ... -
struts+spring+hibernate的web应用<三> Service层代码编写
2012-02-13 00:46 815前面的文章: ... -
struts+spring+hibernate的web应用<二> Dao层代码编写
2012-02-13 00:45 825前一篇文章 (struts+spring ... -
struts+spring+hibernate的web应用<一> 架构搭建
2012-02-13 00:44 743许久没有些文章了,现 ... -
检测一个字符串是否在jvm的常量池中(原创)
2012-01-11 09:07 2117检测一个字符串是否在jvm的常量池中 public ... -
我写的密码强度验证方法(原创)
2011-12-18 15:26 8316/* *说明: * 该方法主要分析密码的内容构成 ...
相关推荐
mybatis添加ehcache缓存支持,基于maven项目管理
基于SpringBoot+Layui搭建的学生管理系统源码,融合shiro安全框架和Ehcache缓存框架.zip基于SpringBoot+Layui搭建的学生管理系统源码,融合shiro安全框架和Ehcache缓存框架.zip 【备注】 该项目是个人毕设项目,...
【EhCache】Java缓存框架使用EhCache结合Spring AOP EhCache是一个纯Java的进程内缓存框架,具有如下特点: 1. 快速简单,非常容易和应用集成。... 支持多缓存管理器实例,以及一个实例的多个缓存区域 等特点。
1、基于SpringBoot+Layui+shiro安全框架和Ehcache缓存框架搭建的学生管理系统源码+项目说明.zip 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末...
基于SpringBoot+Layui搭建的学生管理系统,融合shiro安全框架和Ehcache缓存框架
ehcache是一个用Java实现的使用简单,高速,实现线程安全的缓存管理类库,ehcache提供了用内存,磁盘文件存储,以及分布式存储方式等多种灵活的cache管理方案,是hibernate中默认的CacheProvider。
EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的... 具有缓存和缓存管理器的侦听接口8. 支持多缓存管理器实例,以及一个实例的多个缓存区域9. 提供Hibernate的缓存实现10. 等等
EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider... 支持多缓存管理器实例,以及一个实例的多个缓存区域9. 提供Hibernate的缓存实现10. 等等 标签:缓存
2、ehcache 、redis 通过缓存管理器管理 3、可分别设置缓存的过期时间 ehcache :添加依赖 pom.xml 2、添加配置文件ehcache.xml 3、添加注解@EnableCaching @Cacheable 4、插入缓存 5 读取缓存 6 设置缓存过期时间...
为您提供EhcacheJava缓存框架下载,EhCache 是一个纯Java的进程内缓存框架,具有快速、精干等特点,是Hibernate中默认的CacheProvider。... 具有缓存和缓存管理器的侦听接口8. 支持多缓存管理器实例,
二级缓存 :是SessionFactory对象缓存,可以被创建出的多个 Session 对象共享,二级缓存默认是关闭的,如果要使用需要手动开启,并且依赖EhCache组件。 三级缓存 :查询缓存,配置开启该缓存的情况下,重复使用一...
基于java的程序源码及相关资料