当前位置: 首页 > news >正文

网站建设会议讲话lol视频网站源码

网站建设会议讲话,lol视频网站源码,站长之家官网登录入口,网站自适应屏幕转载注明出处http://blog.csdn.net/u013142781 一、ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架#xff0c;具有快速、精干等特点#xff0c;是Hibernate中默认的CacheProvider。Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。… 转载注明出处http://blog.csdn.net/u013142781 一、ehcahe的介绍 EhCache 是一个纯Java的进程内缓存框架具有快速、精干等特点是Hibernate中默认的CacheProvider。Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储缓存加载器,缓存扩展缓存异常处理程序一个gzip缓存servlet过滤器支持REST和SOAP api等特点。 优点  1. 快速  2. 简单  3. 多种缓存策略  4. 缓存数据有两级内存和磁盘因此无需担心容量问题  5. 缓存数据会在虚拟机重启的过程中写入磁盘  6. 可以通过RMI、可插入API等方式进行分布式缓存  7. 具有缓存和缓存管理器的侦听接口  8. 支持多缓存管理器实例以及一个实例的多个缓存区域  9. 提供Hibernate的缓存实现 缺点  1. 使用磁盘Cache的时候非常占用磁盘空间这是因为DiskCache的算法简单该算法简单也导致Cache的效率非常高。它只是对元素直接追加存储。因此搜索元素的时候非常的快。如果使用DiskCache的在很频繁的应用中很快磁盘会满。  2. 不能保证数据的安全当突然kill掉java的时候可能会产生冲突EhCache的解决方法是如果文件冲突了则重建cache。这对于Cache数据需要保存的时候可能不利。当然Cache只是简单的加速而不能保证数据的安全。如果想保证数据的存储安全可以使用Bekeley DB Java Edition版本。这是个嵌入式数据库。可以确保存储安全和空间的利用率。 EhCache的分布式缓存有传统的RMI1.5版的JGroups1.6版的JMS。分布式缓存主要解决集群环境中不同的服务器间的数据的同步问题。 使用Spring的AOP进行整合可以灵活的对方法的返回结果对象进行缓存。 下面将介绍SpringEhCache详细实例。 二、详细实例讲解 本实例的环境 eclipse maven spring ehcache junit 2.1、相关依赖pom.xml project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.luo/groupIdartifactIdehcache_project/artifactIdversion0.0.1-SNAPSHOT/versionproperties!-- spring版本号 --spring.version3.2.8.RELEASE/spring.version!-- junit版本号 --junit.version4.10/junit.version/propertiesdependencies!-- 添加Spring依赖 --dependencygroupIdorg.springframework/groupIdartifactIdspring-core/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-context-support/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-aop/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-aspects/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-tx/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion${spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-web/artifactIdversion${spring.version}/version/dependency!--单元测试依赖 --dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion${junit.version}/versionscopetest/scope/dependency!--spring单元测试依赖 --dependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactIdversion${spring.version}/versionscopetest/scope/dependency!-- ehcache 相关依赖 --dependencygroupIdnet.sf.ehcache/groupIdartifactIdehcache/artifactIdversion2.8.2/version/dependency/dependencies /project 2.2、添加ehcache配置文件ehcache-setting.xml?xml version1.0 encodingUTF-8? ehcache!-- 指定一个文件目录当EhCache把数据写到硬盘上时将把数据写到这个文件目录下 --diskStore pathjava.io.tmpdir/!-- 设定缓存的默认数据过期策略 --defaultCachemaxElementsInMemory10000 eternalfalse overflowToDisktruetimeToIdleSeconds10timeToLiveSeconds20diskPersistentfalsediskExpiryThreadIntervalSeconds120/cache namecacheTestmaxElementsInMemory1000eternalfalseoverflowToDisktruetimeToIdleSeconds10timeToLiveSeconds20//ehcache这里我们配置了cacheTest策略10秒过期。 cache元素的属性 name缓存名称 maxElementsInMemory内存中最大缓存对象数 maxElementsOnDisk硬盘中最大缓存对象数若是0表示无穷大 eternaltrue表示对象永不过期此时会忽略timeToIdleSeconds和timeToLiveSeconds属性默认为false overflowToDisktrue表示当内存缓存的对象数目达到了 maxElementsInMemory界限后会把溢出的对象写到硬盘缓存中。注意如果缓存的对象要写入到硬盘中的话则该对象必须实现了Serializable接口才行。 diskSpoolBufferSizeMB磁盘缓存区大小默认为30MB。每个Cache都应该有自己的一个缓存区。 diskPersistent是否缓存虚拟机重启期数据是否持久化磁盘缓存,当这个属性的值为true时,系统在初始化时会在磁盘中查找文件名为cache名称,后缀名为index的文件这个文件中存放了已经持久化在磁盘中的cache的index,找到后会把cache加载到内存要想把cache真正持久化到磁盘,写程序时注意执行net.sf.ehcache.Cache.put(Element element)后要调用flush()方法。 diskExpiryThreadIntervalSeconds磁盘失效线程运行时间间隔默认为120秒 timeToIdleSeconds 设定允许对象处于空闲状态的最长时间以秒为单位。当对象自从最近一次被访问后如果处于空闲状态的时间超过了timeToIdleSeconds属性值这个对象就会过期EHCache将把它从缓存中清空。只有当eternal属性为false该属性才有效。如果该属性值为0则表示对象可以无限期地处于空闲状态 timeToLiveSeconds设定对象允许存在于缓存中的最长时间以秒为单位。当对象自从被存放到缓存中后如果处于缓存中的时间超过了 timeToLiveSeconds属性值这个对象就会过期EHCache将把它从缓存中清除。只有当eternal属性为false该属性才有效。如果该属性值为0则表示对象可以无限期地存在于缓存中。timeToLiveSeconds必须大于timeToIdleSeconds属性才有意义 memoryStoreEvictionPolicy当达到maxElementsInMemory限制时Ehcache将会根据指定的策略去清理内存。可选策略有LRU最近最少使用默认策略、FIFO先进先出、LFU最少访问次数。 2.3、spring配置文件application.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xmlns:cachehttp://www.springframework.org/schema/cachexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocation http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd!-- 自动扫描注解的bean --context:component-scan base-packagecom.luo.service /cache:annotation-driven cache-managercacheManager / bean idcacheManager classorg.springframework.cache.ehcache.EhCacheCacheManager property namecacheManager refehcache/property /bean bean idehcache classorg.springframework.cache.ehcache.EhCacheManagerFactoryBean property nameconfigLocation valueclasspath:ehcache-setting.xml/property /bean /beans 2.4、EhCacheTestService接口package com.luo.service;public interface EhCacheTestService {public String getTimestamp(String param); } 2.5、EhCacheTestService接口实现package com.luo.service.impl;import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.luo.service.EhCacheTestService;Service public class EhCacheTestServiceImpl implements EhCacheTestService {Cacheable(valuecacheTest,key#param)public String getTimestamp(String param) {Long timestamp System.currentTimeMillis();return timestamp.toString();}} 这里注解中value”cacheTest”与ehcache-setting.xml中的cache名称属性值一致。2.6、单元测试类 package com.luo.baseTest;import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; //指定bean注入的配置文件 ContextConfiguration(locations { classpath:application.xml }) //使用标准的JUnit RunWith注释来告诉JUnit使用Spring TestRunner RunWith(SpringJUnit4ClassRunner.class) public class SpringTestCase extends AbstractJUnit4SpringContextTests {} 1 2 3 4 5 6 7 8 9 10 11 12 13 14 package com.luo.service;import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired;import com.luo.baseTest.SpringTestCase;public class EhCacheTestServiceTest extends SpringTestCase {Autowired private EhCacheTestService ehCacheTestService;Test public void getTimestampTest() throws InterruptedException{ System.out.println(第一次调用 ehCacheTestService.getTimestamp(param));Thread.sleep(2000);System.out.println(2秒之后调用 ehCacheTestService.getTimestamp(param));Thread.sleep(11000);System.out.println(再过11秒之后调用 ehCacheTestService.getTimestamp(param));} } 2.7、运行结果三、工程源码下载 http://download.csdn.net/detail/u013142781/9401689
http://www.pierceye.com/news/241494/

相关文章:

  • 深圳市哪些公司做网站好wordpress小插件下载地址
  • 佛山优化网站公司网站策划书格式及范文
  • 上海网站建设公司秦皇岛网站seo
  • 外贸网站推广 sit淮安市广德育建设网站
  • 准备建网站该怎么做淘宝店铺
  • 1688外贸网站国外购物网站哪个最好
  • 怎么修改网站关键词网站建设的地方
  • 江苏运营网站建设业务淘宝推广引流方法有哪些
  • 快手评论点赞网站建设专业分站微信小程序开发者中心
  • mvc5网站开发之六 管理员p2网站模板
  • 黄页网站推广公司网站建设公司包括哪些内容
  • 网站平台建设目标修改网站j广州网络公司
  • 网站制作商城正规免费发布信息网站
  • 建设企业网站的人员组成莱芜网站建设费用
  • 长春建站网站西宁做网站君博专注
  • 学校实验室网站建设现状怎么做网站 ppt
  • 网站建设骗子公司新开传奇网站发布网
  • 智能模板网站建设方案深圳团购网站设计
  • 网站建设和网页设计用wordpress做网站页面显示404
  • 网站首页百度收录怎么做做装修公司网站
  • 湛江网站排名提升免费网站空间有什么用
  • 装修公司网站 源码绍兴市交通建设检测中心网站
  • 企业建设网站流程图珠海网站建设 旭洁
  • 企业商城网站开发互联网行业公司
  • 中国建设人才服务信息网是正规网站wordpress文章分享
  • 渭南网站建设公司电话央美老师做的家具网站
  • 机械网站建设栏目内容怎么欣赏一个网站设计图
  • 帝国cms 网站搬家wordpress 购物 插件下载
  • 怎么做ppt教程网站手机能访问asp网站
  • 电子商务网站建设与管理教材评价织梦网站地图调用全站文章