ehcache 缓存管理工具
<ehcache><diskStore path="java.io.tmpdir" /><defaultCache maxElementsInMemory="10000" eternal="false"timeToIdleSeconds="1800" timeToLiveSeconds="1800"overflowToDisk="false" /><cache name="shortcache" maxElementsInMemory="10000" eternal="false"overflowToDisk="false" timeToIdleSeconds="600"timeToLiveSeconds="600" /><cache name="middlecache" maxElementsInMemory="50000"eternal="false" overflowToDisk="false" timeToIdleSeconds="1800"timeToLiveSeconds="1800" /><cache name="longcache" maxElementsInMemory="10000" eternal="false"overflowToDisk="false" timeToIdleSeconds="3600"timeToLiveSeconds="3600" /><cache name="morelongcache" maxElementsInMemory="50000"eternal="false" overflowToDisk="false" timeToIdleSeconds="864000"timeToLiveSeconds="864000" /></ehcache>
<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><listener><listener-class>com.dadi.oa.init.InitListener</listener-class></listener>
package com.dadi.oa.init;import java.util.ArrayList;import java.util.List;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;public class InitListener implements ServletContextListener {private static List<InitHandler> initHandlerList=new ArrayList<InitHandler>();static {initHandlerList.add(new InitEhcacheHandler());}public void contextDestroyed(ServletContextEvent arg0) {// TODO Auto-generated method stub}public void contextInitialized(ServletContextEvent servletContextEvent) {if (initHandlerList != null && initHandlerList.size() > 0) {for (InitHandler initHandler : initHandlerList) {try {initHandler.init(servletContextEvent.getServletContext());} catch (RuntimeException e) {e.printStackTrace();}}}}}
package com.dadi.oa.init;import javax.servlet.ServletContext;public interface InitHandler {public void init(ServletContext servletContext);}
package com.dadi.oa.init;import java.io.File;import javax.servlet.ServletContext;import com.dadi.oa.util.CacheFactory;import net.sf.ehcache.CacheManager;public class InitEhcacheHandler implements InitHandler {public void init(ServletContext servletContext) {String realpath = servletContext.getRealPath("/WEB-INF/ehcache.xml").replace('/',File.separatorChar);CacheManager cacheManager = new CacheManager(realpath);CacheFactory.setCacheManager(cacheManager);}}
package com.dadi.oa.util;import net.sf.ehcache.Cache;import net.sf.ehcache.CacheManager;import org.apache.commons.lang.StringUtils;public class CacheFactory {private static CacheManager cacheManager ;public static Cache getCacheByName(String cachename) {if (StringUtils.isEmpty(cachename)) {System.out.println("cachename must be not empty");return null;}Cache cache = cacheManager.getCache(cachename);if (cache == null) {System.out.println("no cache named : " + cachename + "has defined. ");return null;}return cache;}/***<pre><cache name="cachekey" maxElementsInMemory="50000"eternal="false" overflowToDisk="false" timeToIdleSeconds="864000"timeToLiveSeconds="864000" /></pre>功能:获取cache,不存在时,自动创建,options为可选配置参数* @param options [memory,liveSeconds, idleSeconds]* @param cacheName* @return*/public static Cache getCache(String cacheName,int...options) {int memory=10000, liveSeconds=864000, idleSeconds=864000;//shortcacheif (options!=null&&options.length>0) {memory = options[0];liveSeconds=options.length>1?options[1]:liveSeconds;idleSeconds=options.length>2?options[1]:idleSeconds;}Cache cache = getCacheByName(cacheName);if(cache==null){cache = new Cache(cacheName, memory, false, false, liveSeconds, idleSeconds);cacheManager.addCache(cache);System.out.println("the cache " + cacheName + " has created dynamically. ");}return cache;}public synchronized static void setCacheManager(CacheManager cacheManager) {CacheFactory.cacheManager = cacheManager;}}
/*** 获取公文证明列表* @param mapping* @param form* @param request* @param response* @return* @throws Exception*/public ActionForward provelist(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {String msgid = RequestUtil.getRequestInfo(request, "msgid");String resultList_en_ = RequestUtil.getRequestInfo(request, "resultList_en_");CommonListVo commonListVo = CacheFactory.getCache("shortcache").get("commonListVo"+msgid) == null? null ://获取缓存(CommonListVo)BeanUtils.cloneBean(CacheFactory.getCache("shortcache").get("commonListVo"+msgid).getObjectValue());if(null !=resultList_en_ && resultList_en_.equalsIgnoreCase("output.xls")){logger.info("---------------prove list execl export .......-----------");// modfiedExportData(commonListVo.getDataList());}else{logger.info("---------------get prove list begin -----------");if(null == commonListVo){Map retMap = oaProveManageService.getUserProveList(msgid);if(retMap.get("resultStr").toString().equalsIgnoreCase("fail")){request.setAttribute("info", "数据库繁忙,请稍候再试!");request.setAttribute("closepage", "yes");}commonListVo = new CommonListVo();commonListVo.setColumnList((ArrayList)genECColumnsList());commonListVo.setDataList((ArrayList)retMap.get("provelist"));commonListVo.setExportFlag(true);commonListVo.setActionTo("/oaproverpt.do");commonListVo.setPagesize(100);//设置缓存CacheFactory.getCacheByName("shortcache").put(new Element("commonListVo"+msgid, BeanUtils.cloneBean(commonListVo)));}commonListVo.setDataList((ArrayList)genECDataList((List)commonListVo.getDataList(),request.getServerName()));logger.info("---------------get prove list end -----------");}request.setAttribute("commonListVo", commonListVo);return mapping.findForward("success");}

附件列表
ehcache 缓存管理工具的更多相关文章
- Shiro入门之二 --------基于注解方式的权限控制与Ehcache缓存
一 基于注解方式的权限控制 首先, 在spring配置文件applicationContext.xml中配置自动代理和切面 <!-- 8配置自动代理 --> <bean cl ...
- 业务逻辑:五、完成认证用户的动态授权功能 六、完成Shiro整合Ehcache缓存权限数据
一. 完成认证用户的动态授权功能 提示:根据当前认证用户查询数据库,获取其对应的权限,为其授权 操作步骤: 在realm的授权方法中通过使用principals对象获取到当前登录用户 创建一个授权信息 ...
- Spring Boot 2.x基础教程:EhCache缓存的使用
上一篇我们学会了如何使用Spring Boot使用进程内缓存在加速数据访问.可能大家会问,那我们在Spring Boot中到底使用了什么缓存呢? 在Spring Boot中通过@EnableCachi ...
- 简单聊聊Ehcache缓存
最近工作没有那么忙,有时间来写写东西.今年的系统分析师报名已经开始了,面对历年的真题,真的难以入笔,所以突然对未来充满了担忧,还是得抓紧时间学习技术. 同事推了一篇软文,看到了这个Ehcache,感觉 ...
- Spring自定义缓存管理及配置Ehcache缓存
spring自带缓存.自建缓存管理器等都可解决项目部分性能问题.结合Ehcache后性能更优,使用也比较简单. 在进行Ehcache学习之前,最好对Spring自带的缓存管理有一个总体的认识. 这篇文 ...
- JAVAEE——BOS物流项目12:角色、用户管理,使用ehcache缓存,系统菜单根据登录人展示
1 学习计划 1.角色管理 n 添加角色功能 n 角色分页查询 2.用户管理 n 添加用户功能 n 用户分页查询 3.修改Realm中授权方法(查询数据库) 4.使用ehcache缓存权限数据 n 添 ...
- SpringMVC + Mybatis + Shiro + ehcache时缓存管理器报错。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' ...
- SpringBoot2 整合Ehcache组件,轻量级缓存管理
本文源码:GitHub·点这里 || GitEE·点这里 一.Ehcache缓存简介 1.基础简介 EhCache是一个纯Java的进程内缓存框架,具有快速.上手简单等特点,是Hibernate中默认 ...
- Hibernate性能优化之EHCache缓存
像Hibernate这种ORM框架,相较于JDBC操作,需要有更复杂的机制来实现映射.对象状态管理等,因此在性能和效率上有一定的损耗. 在保证避免映射产生低效的SQL操作外,缓存是提升Hibernat ...
随机推荐
- Struts中的常量
以下是Struts中常量的一些经常使用配置,保存下来留作积累吧. <?xml version="1.0" encoding="UTF-8"?> &l ...
- 【Docker】安装tomcat并部署应用
安装tomcat 1.拉取tomcat镜像 docker pull docker.io/tomcat 查看镜像 docker images 2.启动tomcat 首先添加8090端口:firewall ...
- 安装mysql 和 apache
一. 安装apache服务器 1. 检查apache服务器是否安装 #service httpd status 2. 如提示未被识别的服务,则表明组件未安装,需手动安装 #yum install ht ...
- Job for vsftpd.service failed because the control process exited with error code
# systemctl start vsftpd.serviceJob for vsftpd.service failed because the control process exited wit ...
- linux shutdown命令
shutdown [-t 秒] [-arkhncfF] 时间 [警告信息] 常用选项与参数: -t sec : -t 后面加秒数,亦即『过几秒后关机』的意思 -k : 不要真的关机,只是发送警告信息出 ...
- .NET Remoting三种信道Http,Tcp,IPC和Web Service的访问速度比较(转)
Remoting和Web Service是.net中的重要技术,都可用来实现分布式系统开发,如果是不同的平台就只能选择Web Service,但如果是同一平台,就都可以选择了.到底选择那种,当然还有访 ...
- 转载:【微信小程序】 wx:if 与 hidden(隐藏元素)区别
条件渲染 顾名思义所谓的条件渲染,就是通过条件来判断是否需要渲染该代码块.条件渲染主要是用到wx:if 和 block wx:if 这两个,第一个相信好理解,第二个是在block里面进行条件渲染,这里 ...
- js createElement appendChild createTextNode用法
xml不支持innerHTML 1 <p id="bj">北京</p> <script type="text/javascript" ...
- HDUOJ ------1398
http://acm.hdu.edu.cn/showproblem.php?pid=1398 Square Coins Time Limit: 2000/1000 MS (Java/Others) ...
- 创建 StyledMapType 地图样式
您可以通过创建 StyledMapType 并向构造函数传递特征和样式器信息,新建作为样式应用对象的地图类型.此方法不会影响默认地图类型的样式. 如需新建地图类型: 创建您的样式数组.请参阅“地图特征 ...