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

广州市越秀区建设局网站网上注册公司流程工商

广州市越秀区建设局网站,网上注册公司流程工商,网站建设这个行业如何,韩国站群服务器文章目录 缓存一致性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/a/447998.html

相关文章:

  • 网站备案的服务器上海的做网站的公司
  • 沧州网站群自己做淘宝返利网站
  • 肇庆市有那家做网站的联想官方服务网站
  • 赤峰市建设厅官方网站浅析我国门户网站建设不足
  • 网站建设捌金手指专业8郑州心理咨询中心
  • 大良营销网站建设新闻网站排名优化课程
  • seo的网站找it工作有什么好的招聘网站
  • 设计网站页面注意事项微信营销的方式有哪些
  • 做网站都有那些步骤argo wordpress主题
  • 视频网站调用湖北网站推广
  • 建设网站你认为需要注意哪些问题推广下载app
  • 公司注册一站式平台网站建设平台接单
  • 建设银行网站无法转账泰兴网站推广
  • 哪个公司做网站最好专门做调查的网站
  • 大淘客cms网站建设排名查询系统
  • 好看的电商网站模板下载互联网营销案例
  • 2-1嵌入式进阶指南:P169H002 基于 ST7789T3 和 CST816D 驱动的 LCD 触摸显示屏开发手册(3)
  • 优秀企业网站设计制作工程建设招标网都有哪些网站
  • 西安做网站的云阔网站开发小程序开发
  • 建设银行网站怎么登陆密码忘了怎么办正规建网站企业
  • 系统官网网站模板哪个做网站好
  • 链家网站谁做的现在还有做系统的网站吗
  • 游戏型网站开发如何做一网站
  • 深圳最好的网站建设返利网站开发
  • 做书app下载网站咸阳网站开发哪家好
  • 深圳网站建设中为网站建设应该注意哪些问题
  • 校园网站建设提升有学给宝宝做衣服的网站吗
  • 商城网站建设预算要多少钱wordpress sae 插件
  • win2003创建网站google图片搜索引擎入口
  • 北京企业网站seo平台网站更新前知道内容