Java Ecache缓存工具类源码下载
Java Ecache缓存工具类源代码复制到编译器,调用即可:
public class EcacheUtil {
public static CacheManager manager = CacheManager.getInstance();//找到ehcache.xml的路径
public static Cache cache = manager.getCache("cache");//cache 的值取的是ehcache.xml中的name
/**
* 根据key查找缓存
* @param key
* @return
*/
public static Object getObjectCached(String key){
Element element1 = cache.get(key);
if(element1==null){
return null;
}else{
return element1.getValue();
}
}
/**
* 添加缓存
* @param key
* @param value
*/
public static void setObjectCached(String key,Object value){
cache.put(new Element(key, value));
}
/**
* 删除全部缓存
*/
public static void delObjectCachedall(){
cache.removeAll();
}
/**
* 卸载缓存
*/
public static void xiezaiObjectCached(){
manager.shutdown();
}
}
调用里面的方法事例:
//查找
public void main(){
Object cachevalue=EcacheUtil.getObjectCached("key");
if(cachevalue!=null){
System.out.println("key里面保存的值:"+cachevalue.toString());
}else{
System.out.println("key还没有添加到cache缓存中!");
}
}
//添加
public void main2(){
EcacheUtil.setObjectCached("key", "来自淘拜网!");
}
正在加载评论...
相关文章
- 新建的springboot项目接口返回乱码的解决方法
- 配置@ConfigurationProperties后读取yml文件的参数...
- Caused by: java.lang.NoClassDefFoundError: Coul...
- springboot加入SSL证书设置https访问
- Springboot用pagehelper分页插件查询Oracle的速度...
- shiro的登录账号密码校验过程,SimpleAuthenticati...
- Shiro控制没有登录时,返回指定JSON格式数据
- SpringBoot中mybatis返回的Date时间格式化
- ClassNotFoundException: org.aspectj.lang.annota...
栏目列表
推荐阅读
- java的StringEscapeUtils转义与反转义
- Mybatis的foreach事列,如何获取foreach的index值
- Java Ehcache缓存的timeToIdleSeconds和timeToLiveSeconds区别
- errcode: 40001, errmsg: invalid credential, access_token is invalid or not latest rid: 5f6981c2-6cc9cb20-6833977a
- Java四种线程池newCachedThreadPool,newFixedThreadPool,newScheduledThreadPool,newSingleThreadExecutor
- 服务器侦听端口 netstat -na 命令详解
- tomcat启动maven工程报错-Updating status for Tomcat v7.0 Server at localhost...
- Mybatis异常There is no getter for property named 'XXX' in 'class java.lang.String'
- Java后台获取当前访问客户端的真实IP地址(外网或内网地址)
- com.googlecode.aviator.AviatorEvaluator规则引擎用法
- java发送http的get、post请求
- StringSubstitutor替换占位符,处理SQL参数
- java拦截器HandlerInterceptor的preHandle、postHandle与afterCompletion三个方法
- java中Session缓存和Cache缓存的区别
- Java8对象集合转List<Integer>id集合,转List<String>name集合,List<Class>对象集合
- Java导出excel利用jxls合并单元格jx:mergeCells实现表格嵌套技术
- java图片文件base64流之间的互转帮助类源码下载
- 利用ObjectMapper,将json数组转List<Map<String,Object>>
- java的DES加密解密辅助类
- IllegalArgumentException: Illegal base64 character 3a