zoukankan      html  css  js  c++  java
  • 关于springboot2.x 的 RedisCacheManager变化

    前言:

    springboot配置缓存过期时间,大部分是使用ReidsCacheManager来进行自定义的配置。

    以下是大部分网上的代码(这也是基于springboot1.x的版本可以使用的)

    @Bean
    public CacheManager cacheManager(RedisTemplate redisTemplate) {
        RedisCacheManager cacheManager= new RedisCacheManager(redisTemplate);
        cacheManager.setDefaultExpiration(60);
        Map<String,Long> expiresMap=new HashMap<>();
        expiresMap.put("Product",5L);
        cacheManager.setExpires(expiresMap);
        return cacheManager;
    }

    然而在springboot2.x中,RedisCacheManager已经没有了单参数的构造方法。

    以下是springboot2.x版本下 RedisCacheManager的大部分方法:

    @Bean
    public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofHours(1)); // 设置缓存有效期一小时
        return RedisCacheManager.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory)).cacheDefaults(redisCacheConfiguration).build();
    }
  • 相关阅读:
    windows7通过Dns.GetHostAddresses(Dns.GetHostName())获得ipv6地址转换到ipv4
    题解 P3829 【[SHOI2012]信用卡凸包】
    点积与叉积
    点分治
    珂朵莉树
    NOIP2020模拟赛(二十五)7.26 结题报告
    树连剖分
    NOIP2020模拟赛(拾)解题报告
    题解 P2538 【[SCOI2008]城堡】
    模拟退火
  • 原文地址:https://www.cnblogs.com/ZJOE80/p/10656501.html
Copyright © 2011-2022 走看看