单独使用EHCache
来源:互联网 发布:电子日历制作软件 编辑:程序博客网 时间:2024/05/22 17:18
1.创建CacheManager (net.sf.ehcache.CacheManager)
(1)使用默认配置文件创建
1
CacheManager manager = CacheManager.create();
(2)使用指定配置文件创建
1
CacheManager manager = CacheManager.create(
"src/config/ehcache.xml"
);
(3)从classpath找寻配置文件并创建
1
URL url = getClass().getResource(
"/anothername.xml"
);
2
CacheManager manager = CacheManager.create(url);
(4)通过输入流创建
1
InputStream fis =
new
FileInputStream(
new
File(
"src/config/ehcache.xml"
).getAbsolutePath());
2
try
{
3
manager = CacheManager.create(fis);
4
}
finally
{
5
fis.close();
6
}
2.创建Caches (net.sf.ehcache.Cache)
(1)取得配置文件中预先 定义的sampleCache1设置,生成一个Cache
1
Cache cache = manager.getCache(
"sampleCache1"
);
(2)设置一个名为test 的新cache,test属性为默认
1
CacheManager manager = CacheManager.create();
2
manager.addCache(
"test"
);
(3)设置一个名为test 的新cache,并定义其属性
1
CacheManager manager = CacheManager.create();
2
Cache cache =
new
Cache(
"test"
,
1
,
true
,
false
,
5
,
2
);
3
manager.addCache(cache);
(4)删除cache
1
CacheManager singletonManager = CacheManager.create();
2
singletonManager.removeCache(
"sampleCache1"
);
3.使用Caches
(1)往cache中加入元素
1
Element element =
new
Element(
"key1"
,
"value1"
);
2
cache.put(
new
Element(element);
(2)从cache中取得元素
1
Element element = cache.get(
"key1"
);
(3)从cache中删除元素
1
Cache cache = manager.getCache(
"sampleCache1"
);
2
Element element =
new
Element(
"key1"
,
"value1"
);
3
cache.remove(
"key1"
);
4.卸载CacheManager ,关闭Cache
1
manager.shutdown();
0 0
- EHCache 单独使用
- 单独使用EHCache
- EHCache入门系列(二)–在工程中单独使用
- EHCache入门系列(二)–在工程中单独使用
- EHCache入门系列(二)–在工程中单独使用
- web项目 ehcache 单独配置
- 使用ehcache
- 使用ehcache
- 使用ehcache
- ehcache使用
- Ehcache 使用
- Ehcache 使用
- 使用ehcache
- EHCACHE使用
- ehcache使用
- ehcache使用
- EHCache使用
- EHCache使用
- Comparable和Comparator的区别
- 完美解决Nginx配置反向代理时出现的13: Permission denied) while connecting to upstream, client: 127.0.0.1
- printf
- phpMyAdmin使用教程:[2]用户及权限管理
- webview和h5的交互
- 单独使用EHCache
- Android Studio 开发JNI工程步骤
- C# 重构之四(提取接口重构)
- xml tomcat 关系
- Kafka分布式消息队列框架
- arrayList——list和arrayList区别
- VB是否过时?
- oracle数据库使用学习
- caffe的LMDB数据库输入数据类型由char改为float