package com.kocla.common.util;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
/**
* 缓存工具类
* @author admin
*
*/
public class EHCache {
private static CacheManager manager;
static{
manager=CacheManager.create();
}
public EHCache(){}
private static class LazyHolder{
private static final EHCache ehcache=new EHCache();
}
public static EHCache getInstance(){
return LazyHolder.ehcache;//内部类单例
}
public Cache getCache(String cacheName){
return manager.getCache(cacheName);
}
//(Course) EHCache.getInstance().findCache("courseCache",
//Constant.OK_COURSE_ + courseId);
//查找缓存数据
public Object findCache(String cacheName,String key){
Cache cache=this.getCache(cacheName);
Element element=null;
if(cache!=null){
element=cache.get(key);
}
if(element==null){
return null;
}
return element.getValue();
}
//保存对象到缓存中
public void saveOrUpdateCache(String cacheName,Object obj,Object key){
Cache cache=this.getCache(cacheName);
Element element=new Element(key, obj);
if(cache!=null){
cache.put(element);//把对象数据存入缓存
}
}
//删除缓存数据
public void removeCache(String cacheName,String key){
if(this.getCache(cacheName)!=null){
getCache(cacheName).remove(key);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CacheManagerDemo.rar (43个子文件)
CacheManagerDemo
.project 1KB
.settings
.jsdtscope 522B
org.eclipse.wst.common.component 584B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.common.project.facet.core.xml 414B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
conf
log4j.properties 4KB
ehcache.xml 4KB
WebRoot
WEB-INF
web.xml 668B
lib
ehcache-core-2.5.2.jar 1.18MB
ehcache-spring-annotations-1.2.0.jar 122KB
slf4j-log4j12-1.6.1.jar 10KB
log4j-1.2.17.jar 478KB
guava-13.0.1.jar 1.8MB
ehcache-terracotta-2.5.2.jar 875KB
slf4j-api-1.6.1.jar 25KB
cglib-nodep-2.2.jar 315KB
terracotta-toolkit-1.5-runtime-4.2.0.jar 12.17MB
classes
log4j.properties 4KB
com
kocla
bena
User.class 1KB
servlet
CacheServlet.class 2KB
common
util
ServiceProxyFactory.class 2KB
Proxy.class 482B
IServiceProxyFactory.class 272B
EHCache$LazyHolder.class 623B
EHCache.class 2KB
LocalProxyHandler.class 2KB
service
ICacheService.class 272B
CacheServiceImpl.class 586B
ehcache.xml 4KB
index.jsp 834B
META-INF
MANIFEST.MF 39B
src
com
kocla
bena
User.java 489B
servlet
CacheServlet.java 1KB
common
util
EHCache.java 1KB
IServiceProxyFactory.java 115B
Proxy.java 351B
ServiceProxyFactory.java 1KB
LocalProxyHandler.java 1KB
service
CacheServiceImpl.java 223B
ICacheService.java 184B
.classpath 1KB
共 43 条
- 1
资源评论
- qq_331757752018-03-05看看是否适合使用
zhanglugen
- 粉丝: 0
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功