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

建设旅游网站的必要性中国商标网官方查询网站

建设旅游网站的必要性,中国商标网官方查询网站,网页设计作业答案,大网站建设规范1. 业务需求 前端用户查询数据时,数据查询缓慢耗费时间; 基于缓存中间件实现缓存方法返回值:实现流程用户第一次查询时在数据库查询,并将查询的返回值存储在缓存中间件中,在缓存有效期内前端用户再次查询时,从缓存中间件缓存获取 2. 基于Redis实现 参考1 2.1 简单实现 引入…1. 业务需求 前端用户查询数据时,数据查询缓慢耗费时间; 基于缓存中间件实现缓存方法返回值:实现流程用户第一次查询时在数据库查询,并将查询的返回值存储在缓存中间件中,在缓存有效期内前端用户再次查询时,从缓存中间件缓存获取 2. 基于Redis实现 参考1 2.1 简单实现 引入cache依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-cache/artifactId/dependency在redis配置类中添加cache缓存机制 /*** redis配置** author ruoyi*/ Configuration EnableCaching public class RedisConfig extends CachingConfigurerSupport {/*** 方法返回值缓存策略** param factory* return*/Beanpublic CacheManager cacheManager(RedisConnectionFactory factory) {RedisCacheConfiguration config RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(2 * 60))//过期超时时间 2分钟.disableCachingNullValues();return RedisCacheManager.builder(factory).cacheDefaults(config).transactionAware().build();}//......其他配置不展示..... }启动类开始方法缓存EnableCaching package com.ruoyi;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.cache.annotation.EnableCaching;/*** 启动程序** author ruoyi*/ SpringBootApplication(exclude { DataSourceAutoConfiguration.class }) EnableCaching public class RuoYiApplication {public static void main(String[] args){// System.setProperty(spring.devtools.restart.enabled, false);SpringApplication.run(RuoYiApplication.class, args);System.out.println((♥◠‿◠) 若依启动成功 ლ(´ڡლ) \n .-------. ____ __ \n | _ _ \\ \\ \\ / / \n | ( ) | \\ _. / \n |(_ o _) / _( )_ . \n | (_,_). __ ___(_ o _) \n | |\\ \\ | || |(_,_) \n | | \\ /| - / \n | | \\ / \\ / \n - - -..- );} } 业务层设置缓存方法 OverrideCacheable(cacheNames selectuserlist,key #user.userId)public ListSysUser selectUserList(SysUser user){return userMapper.selectUserList(user);}测试效果 第一次请求时 第二次请求时,没有查询数据库 查询userId为2的用户 两分钟过后 2.2 设置自定义过期时长 创建RedisCache解析器 package com.ruoyi.framework.config.properties;import com.ruoyi.common.utils.StringUtils; import org.springframework.data.redis.cache.RedisCache; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter;import java.time.Duration;/*** RedisCache解析器*/ public class MyRedisCacheManager extends RedisCacheManager {public MyRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {super(cacheWriter, defaultCacheConfiguration);}Overrideprotected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {//解析name字段if (!StringUtils.isEmpty(name) name.contains(#)) {//获取时间String numStr name.split(#)[1];if (StringUtils.isNumeric(numStr)) {//重置缓存时长return super.createRedisCache(name, cacheConfig.entryTtl(Duration.ofSeconds(Integer.parseInt(numStr))));}}return super.createRedisCache(name, cacheConfig);} } 配置RedisConfig package com.ruoyi.framework.config;import com.ruoyi.framework.config.properties.MyRedisCacheManager; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheWriter; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.data.redis.serializer.StringRedisSerializer;import java.time.Duration;/*** redis配置** author ruoyi*/ Configuration EnableCaching public class RedisConfig extends CachingConfigurerSupport {/*** 方法返回值缓存策略** param factory* return*/Beanpublic CacheManager cacheManager(RedisConnectionFactory factory) {RedisCacheConfiguration config RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(2 * 60))//过期超时时间 2分钟.disableCachingNullValues();// return RedisCacheManager.builder(factory) // .cacheDefaults(config) // .transactionAware() // .build();return new MyRedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(factory), config);}//...............其他配置...略.......... }使用160秒有效 OverrideCacheable(cacheNames selectuserlist#160,key #user.userId)public ListSysUser selectUserList(SysUser user){return userMapper.selectUserList(user);}2.3 注解Cacheable.key 声明访问缓存的键由于缓存本质上是键值存储因此每次调用缓存方法时都需要使用键去访问。缓存数据时使用的 key可以用它来指定。默认是使用方法参数的值。这个 key 可以使用 spEL 表达式来编写。这里的EL表达式可以使用方法参数及它们对应的属性。使用方法参数时我们可以直接使用“#参数名”或者“#p参数index”。 Cacheable(cacheNamesbooks, key#isbn) public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)Cacheable(cacheNamesbooks, key#isbn.rawNumber) public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)Cacheable(cacheNamesbooks, key#p0) public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)Cacheable(cacheNamesbooks, key#p0.rawNumber) public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed) spEL表达式
http://www.w-s-a.com/news/733944/

相关文章:

  • 自建门户网站建设工程质量监理协会网站
  • 为企网站版面设计经历了哪几个阶段
  • 如何直到网站是用什么模板做的怎么在外贸公司拿订单
  • 网站专题制作酒店网站建设考虑的因素
  • 苏州招聘网站建设潍坊网站建设wfxtseo
  • 手机网站特效做互联网平台要多少钱
  • 做网站广告推广平台旅游网站后台管理系统
  • ppt模板下载免费素材网站php网站开发平台下载
  • 网站推广策划报告航空航天可以做游戏可以视频约会的网站
  • 云南建设学院的网站划分切片来做网站
  • 建设视频网站需要什么知识辽阳建设网站
  • 提供o2o网站建设打扑克网站推广软件
  • 制作简单门户网站步骤中国建设局网站查询
  • 漳州专业网站建设网站建设的面试要求
  • 有哪些网站是封面型汕头网站上排名
  • 自动优化网站软件没有了做的新网站做百度推广怎么弄
  • 高陵县建设局网站商标查询网站
  • 郑州建设网站哪家好东莞网络公司排行榜
  • 成都网站开发费用做行程的网站
  • 做地铁建设的公司网站手机网站首页布局设计
  • 福建亨立建设集团有限公司网站搜狗网页游戏大厅
  • 设计网站musil访问量大的网站选择多少流量的服务器何时
  • 公司网站包括哪些内容新网站怎样做外链
  • 淘宝宝贝链接怎么做相关网站广州好蜘蛛网站建设
  • 长春网站制作网页博山区住房和城乡建设局网站
  • 云南大学网站建设解析到网站怎样做
  • 网站维护的要求包括锦溪网站建设
  • 金站网.营销型网站学校安全教育网站建设
  • 临沂市建设局网站公示军事新闻头条2023
  • 购物网网站建设lamp 做网站