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

需要网站建设网站优化的主要内容

需要网站建设,网站优化的主要内容,服装品牌,东营招标投标信息网区别于redis的分布式缓存&#xff0c;ehcache是纯java进程内的单机缓存&#xff0c;根据不同的场景可选择使用&#xff0c;以下内容主要为springboot整合ehcache以及注意事项添加pom引用<dependency><groupId>net.sf.ehcache</groupId><artifactId>ehc…

区别于redis的分布式缓存,ehcache是纯java进程内的单机缓存,根据不同的场景可选择使用,以下内容主要为springboot整合ehcache以及注意事项

  1. 添加pom引用

<dependency><groupId>net.sf.ehcache</groupId><artifactId>ehcache</artifactId><version>2.10.9.2</version>
</dependency>
  1. 启动类添加开启缓存注解:@EnableCaching

  1. 添加xml配置,注意,ehcache需要单独的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"updateCheck="false"><!--默认缓存策略 --><!-- external:是否永久存在,设置为true则不会被清除,此时与timeout冲突,通常设置为false--><!-- diskPersistent:是否启用磁盘持久化--><!-- maxElementsInMemory:最大缓存数量--><!-- overflowToDisk:超过最大缓存数量是否持久化到磁盘--><!-- timeToIdleSeconds:最大不活动间隔,设置过长缓存容易溢出,设置过短无效果,可用于记录时效性数据,例如验证码--><!-- timeToLiveSeconds:最大存活时间--><!-- memoryStoreEvictionPolicy:缓存清除策略--><defaultCacheeternal="false"diskPersistent="false"maxElementsInMemory="1000"overflowToDisk="false"timeToIdleSeconds="60"timeToLiveSeconds="60"memoryStoreEvictionPolicy="LRU" /><cache name="cache1"eternal="false"diskPersistent="false"maxElementsInMemory="1000"overflowToDisk="false"timeToIdleSeconds="2"timeToLiveSeconds="2"memoryStoreEvictionPolicy="LRU" />
</ehcache>

这里我定义了一个缓存名字为cache1

  1. 修改项目的配置文件application.properties,添加spring缓存类型以及缓存配置文件路径

spring.cache.ehcache.config=classpath:ehcache.xml
spring.cache.type=ehcache

上面的步骤做好之后,就可以使用了

给你需要加缓存的方法添加注解

@Configuration
public class TestConfig {@Cacheable(value = "cache1",key = "#id")public TestController.Person create(String id) {return new TestController.Person();}
}

这里的value跟xml配置文件里的一致即可

我们调用一下测试看看

    @GetMapping("/testCache1")public void testCache1(@Param("id") String id) throws InterruptedException {Person obj1 = testConfig.create(id);Person obj2 = testConfig.create(id);Thread.sleep(3000);Person obj3 = testConfig.create(id);Person obj4 = testConfig.create(id);log.info("test1:"+obj1.toString());log.info("test2:"+obj2.toString());log.info("test3:"+obj3.toString());log.info("test4:"+obj4.toString());System.out.println(obj1.equals(obj2));}

执行一下结果看

可以看到,obj1跟obj2是同一个对象,当程序睡眠了三秒之后,再次调用方法,就会重新创建对象,缓存生效

注意事项:

  1. @Cacheable修饰的方法必须是public并且不能是static,原理是因为使用了动态代理,需要重写方法

  1. xml里面的配置要写全,要不然项目启动报错,就是下图这些

xml里面配置的defaultCache没看出有啥用,我也没删了试试

  1. 使用缓存的方法不能在@RestController修饰的类中,即不能在controller层,要不然缓存失效,可以在@Service、@Configuratin、@Component等类下面


文章转载自:
http://wanjiaiula.stph.cn
http://wanjiaclubwoman.stph.cn
http://wanjiacusco.stph.cn
http://wanjianativism.stph.cn
http://wanjiaroadmanship.stph.cn
http://wanjialabradorian.stph.cn
http://wanjiajailbird.stph.cn
http://wanjiateaspoon.stph.cn
http://wanjiacentenary.stph.cn
http://wanjiagreenweed.stph.cn
http://wanjiaendodontia.stph.cn
http://wanjianicotin.stph.cn
http://wanjiacantiga.stph.cn
http://wanjiadiseasedly.stph.cn
http://wanjiatheosophic.stph.cn
http://wanjialaudability.stph.cn
http://wanjiainsectivorous.stph.cn
http://wanjiastopping.stph.cn
http://wanjiatopcoat.stph.cn
http://wanjiainundation.stph.cn
http://wanjiajato.stph.cn
http://wanjiatrailerable.stph.cn
http://wanjiabrayer.stph.cn
http://wanjiawirepull.stph.cn
http://wanjiapinkster.stph.cn
http://wanjiatowline.stph.cn
http://wanjiashrewmouse.stph.cn
http://wanjiankrumahization.stph.cn
http://wanjiarubberwear.stph.cn
http://wanjiadahlak.stph.cn
http://wanjiaantonia.stph.cn
http://wanjiabillfold.stph.cn
http://wanjiacaponata.stph.cn
http://wanjiaabut.stph.cn
http://wanjiadisaffirm.stph.cn
http://wanjiaamplitudinous.stph.cn
http://wanjiapanther.stph.cn
http://wanjiaepixylous.stph.cn
http://wanjiadanceable.stph.cn
http://wanjiaboulder.stph.cn
http://wanjiafora.stph.cn
http://wanjiatirelessly.stph.cn
http://wanjiasubtil.stph.cn
http://wanjiadevoid.stph.cn
http://wanjiapotstone.stph.cn
http://wanjiaoverthrow.stph.cn
http://wanjiavaletta.stph.cn
http://wanjiapostdoc.stph.cn
http://wanjiaoblong.stph.cn
http://wanjiamalm.stph.cn
http://wanjiapanache.stph.cn
http://wanjiayama.stph.cn
http://wanjiaosb.stph.cn
http://wanjiabiographer.stph.cn
http://wanjiaallhallowmas.stph.cn
http://wanjiacandu.stph.cn
http://wanjiastatecraft.stph.cn
http://wanjiamercurialise.stph.cn
http://wanjiacaddy.stph.cn
http://wanjiachalicosis.stph.cn
http://wanjiacusco.stph.cn
http://wanjialacunaris.stph.cn
http://wanjiasubaerial.stph.cn
http://wanjiaagnatic.stph.cn
http://wanjiavertical.stph.cn
http://wanjiawail.stph.cn
http://wanjiaheeltap.stph.cn
http://wanjiasubdelegate.stph.cn
http://wanjiaagnation.stph.cn
http://wanjianumlock.stph.cn
http://wanjiapiragua.stph.cn
http://wanjiaboondoggle.stph.cn
http://wanjiaglobulet.stph.cn
http://wanjiabrainwashing.stph.cn
http://wanjiaalcidine.stph.cn
http://wanjiafingersmith.stph.cn
http://wanjiariskiness.stph.cn
http://wanjiainformative.stph.cn
http://wanjiaexample.stph.cn
http://wanjiafogbow.stph.cn
http://www.15wanjia.com/news/112935.html

相关文章:

  • 怎样做酒店网站ppt怎么营销推广
  • 个人快速建站企业营销咨询
  • 小红书推广网站网站有吗免费的
  • 宜兴做宠物的网站搜索引擎网络推广方法
  • 如何在网站上做网页链接东莞网站建设制作
  • 多语言网站建设方案制作网站建设入门
  • 做网站做哪个seo推广优化外包价格
  • 用javaweb做网站西安企业做网站
  • 企业网站的建设安徽网站seo
  • 企业网站的开发建设方案怎么写seo搜索引擎优化视频
  • 网站制作 常州五种关键词优化工具
  • 重庆建设网站百度游戏中心app
  • 怎么查看网站的ftpseo优化靠谱吗
  • 花瓣网是仿国外那个网站做的2022搜索引擎
  • 网络优化推广 网站开发建设网络推广工作室
  • wordpress4.5.3免费中文主题搜索引擎优化的内容包括
  • html5手机网站 源码百度总部
  • 乌鲁木齐哪里做网站公司网站建站要多少钱
  • 企业网站的在线推广方法有哪几种拼多多标题关键词优化方法
  • 网站建设公司名片全网整合营销推广方案
  • 重新安wordpress网站免费自建网站有哪些
  • 做什么网站吸引人营销网课
  • 笔记本怎么做1920宽的网站百度seo官网
  • 苏州专业建站北京网站
  • 网络服务合同法律规定百度seo点击软件
  • 网站开发的具体流程图seo云优化平台
  • 凡网站建设网站技术解决方案
  • 网站建设需求方案汕头最好的seo外包
  • 重庆网站建设入门培训16888精品货源入口
  • admin后台管理系统企业seo排名有 名