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

建设银行第三方网站鉴权湖南seo快速排名

建设银行第三方网站鉴权,湖南seo快速排名,wap网站开发框架,黄岗住房和城乡建设厅官方网站文章目录 缓存一致性Spring Cachepom.xmlapplication.ymlCubemallProductApplication.javaSpringCache改造三级分类MyCacheConfig.java缓存一致性 缓存一致性 锁 设置过期时间 读写锁 设置过期时间 Spring Cache 1.读模式 缓存穿透:查询一个null数据,…

文章目录

  • 缓存一致性
  • Spring Cache
    • pom.xml
    • application.yml
    • CubemallProductApplication.java
    • SpringCache改造三级分类
    • MyCacheConfig.java
    • 缓存一致性

缓存一致性

双写模式

设置过期时间
失效模式
读写锁
设置过期时间

Spring Cache

1.读模式
缓存穿透:查询一个null数据,解决:开启缓存空数据,spring.cache.redis.cache-null-values=true
缓存击穿:大量并发进来查询一个正好过期的数据,解决:加锁
缓存雪崩:大量的key同时过期 解决:加过期时间,spring.cache.redis.time-to-live=3600000
2.写模式:缓存与数据库一致
读写加锁。
引入Canal,感知到MySQL的更新去更新数据库
读多写多,直接去数据库查询就行

pom.xml

        <!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-data-redis --><dependency><groupId>org.springframework.session</groupId><artifactId>spring-session-data-redis</artifactId></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-cache --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-cache</artifactId></dependency>

application.yml

spring:cache:type: redisredis:time-to-live: 3600000cache-null-values: true

CubemallProductApplication.java

package com.xd.cubemall.product;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;@EnableCaching
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.xd.cubemall.product.feign")
public class CubemallProductApplication {public static void main(String[] args) {SpringApplication.run(CubemallProductApplication.class, args);}}

SpringCache改造三级分类

    /*** 使用SpringCache改造三级分类* @return*/@Cacheable(value={"category"}, key = "#root.method.name")public List<CategoryVo> getLevel1Categorys() {System.out.println("缓存不命中,查询数据库。。。");//2.缓存中没有数据,查询数据库,从数据库查询分类数据List<CategoryVo> categoryJsonFromDb = getCategoryJsonFromWithRedissonLock();return categoryJsonFromDb;}

MyCacheConfig.java

package com.xd.cubemall.product.config;import org.springframework.boot.autoconfigure.cache.CacheProperties;
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.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;@Configuration
@EnableCaching
public class MyCacheConfig {@BeanRedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties){RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();//修改key和value的序列号机制config = config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()));config = config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));//将配置文件中的所有配置进行生效CacheProperties.Redis redisProperties = cacheProperties.getRedis();if (redisProperties.getTimeToLive() != null) {config = config.entryTtl(redisProperties.getTimeToLive());}if (redisProperties.getKeyPrefix() != null) {config = config.prefixKeysWith(redisProperties.getKeyPrefix());}if (!redisProperties.isCacheNullValues()) {config = config.disableCachingNullValues();}if (!redisProperties.isUseKeyPrefix()) {config = config.disableKeyPrefix();}return config;}
}

缓存一致性

    /*** 三级菜单的级联更新 (缓存一致性)* @param category*/@CacheEvict(value = "category", key = "'getLevel1Categorys'")@Overridepublic void updateCascade(CategoryEntity category) {this.updateById(category);}
http://www.dtcms.com/wzjs/362510.html

相关文章:

  • 大连网站开发培训福州短视频seo推荐
  • 安徽建设信息网seo外包推广
  • 网站介绍ppt怎么做百度快照收录
  • 龙岗网站 建设seo信科企业网
  • 建公司网站需要多少钱广告联盟看广告赚钱
  • 织梦做中英文网站详细步骤网络优化公司有哪些
  • 西藏做网站企业营销案例
  • 个人网站域名后缀百度爱采购优化
  • 前端网站制作教程东莞seo网站制作报价
  • 网站建设用户登录长春关键词优化公司
  • 河北网站建设公司关键帧
  • 动易论坛官方网站软文推广营销
  • 速成网站建设百度手机助手苹果版
  • 徐汇专业做网站搜索引擎推广方法
  • 专业的app网站开发全网营销系统是干什么的
  • 南充做网站多少钱手机百度ai入口
  • 预付做网站订金怎么做账网站排名优化课程
  • 做代码和网站seo优化方法
  • 网站备案自己备案和代理备案中国最新疫情最新消息
  • 国外网站建设接单东莞网站建设推广
  • 网站建设制作包括哪些渠道推广有哪些方式
  • 天河网站 建设信科网络淘宝seo是什么意思
  • 胶州网站建设dch100广东今日最新疫情通报
  • 深圳网站制作招聘短视频搜索优化
  • 建做网站系统优化的例子
  • 做网站模板用什么框架宁波seo外包
  • 国外做美食的网站有哪些360免费建站网页链接
  • 网站建设中的html合肥网站建设公司
  • 做积分网站晚上免费b站软件
  • 郑州企业网站优化哪家便宜b站推广网站入口mmm