【文件属性】:
文件名称:Ehcache使用
文件大小:159KB
文件格式:DOC
更新时间:2015-07-05 09:15:20
Ehcache使用
Ehcache使用:
CacheManager主要的缓存管理类,一般一个应用为一个实例,如下 CacheManager.create();也可以使用new CacheManager的方式创建
默认的配置文件为ehcache.xml文件,也可以使用不同的配置: CacheManager manager = new CacheManager("src/config/other.xml");
缓存的创建,采用自动的方式
CacheManager singletonManager = CacheManager.create();
singletonManager.addCache("testCache");
Cache test = singletonManager.getCache("testCache");
或者直接创建Cache
CacheManager singletonManager = CacheManager.create();
Cache memoryOnlyCache = new Cache("testCache", 5000, false, false, 5, 2);
manager.addCache(memoryOnlyCache);
Cache test = singletonManager.getCache("testCache");
删除cache
CacheManager singletonManager = CacheManager.create();
singletonManager.removeCache("sampleCache1");
在使用ehcache后,需要关闭
CacheManager.getInstance().shutdown()
网友评论
- 说实话,写的不怎么样。。。读完都没明白,例子跑起来有问题