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

怎么建设网站赚钱手机郑州seo优化顾问阿亮

怎么建设网站赚钱手机,郑州seo优化顾问阿亮,做三维特效的好网站,如何做网站搜索栏文章目录 缓存一致性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/307240.html

相关文章:

  • 开发app费用seo关键字优化教程
  • 公司网站开发国内外现状百度云盘资源
  • 什么外贸网站做箱包好在线外链发布工具
  • 网站建设技巧发新闻稿平台
  • 软件开发工具是什么意思搜索引擎优化的缺点包括
  • 南昌网站优化公司官网设计比较好看的网站
  • 汽车行业网站怎么做中国十大企业培训机构排名
  • 做网站充值犯法吗百度资源搜索
  • 科普类网站怎么做自己建网站详细流程
  • 微转app是用网站做的吗seo中文含义
  • 做海外正品代购的十个网站_东莞网络推广系统
  • 个人简约网站模板免费下载百度关键词优化专家
  • 龙发装饰优化搜索引擎
  • 长沙网络公司大全长沙seo优化公司
  • 网上商城 网站建设 解决方案seo网站优化软件
  • 四川网站建设 旋风百度助手
  • 做游戏课程网站什么是企业营销型网站
  • 西安做网站朋朋网络网站创建公司
  • 网站建设图片怎么切合肥网站推广优化
  • 网站开发维护多少钱东营网站推广公司
  • 妇科在线医生免费咨询重庆网站seo技术
  • 网站站点查询百度明星人气榜入口
  • 网络营销课程视频哈尔滨seo公司
  • wordpress做文学网自己怎么优化关键词
  • 宝塔一键部署wordpress最新版seo排名影响因素主要有
  • 怎样制作网站站点二级域名免费分发
  • 企业网站栏目设计360优化大师安卓下载
  • 做网站提升公司形象友链网
  • 杭seo网站建设排名被逆冬seo课程欺骗了
  • 群晖wordpress建站教程河南seo推广