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的大部分方法

可以发现原来1.x版本的构造方法已经没有了,新的构造方法如图所示。
本人没有看1.x的源码,我发现这里有一个RedisCacheManagerBuilder的内部类,从名字就不难发现这是一个用来构造RedisCacheManager的建造模式的应用吧。
所以以下是本人使用的RedisCacheManager的构造方法(如果定制化要求的话可以修改其中的配置就可以),这里我只设置了缓存失效时间为一小时,如需其他配置可以到RedisCacheConfiguration这个类中去寻找一下。

@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.entryTtl(Duration.ofHours(1)); // 设置缓存有效期一小时
return RedisCacheManager
.builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
.cacheDefaults(redisCacheConfiguration).build();
}

关于springboot2.x 的 RedisCacheManager变化的更多相关文章

  1. springboot2.x 的 RedisCacheManager变化

    springboot2.x 的 RedisCacheManager变化 springboot2.x 的 RedisCacheManager变化 由于最近在学着使用redis做缓存,使用的是spring ...

  2. SpringBoot 1.X版本设置Https访问以及跨域https访问的问题

    最近在做的一个项目中出现了Https域向非Https域发送ajax请求无法通过的问题 Mixed Content: The page at was loaded over HTTPS, but req ...

  3. springboot 2 集成 redis 缓存 序列化

    springboot 缓存 为了实现是在数据中查询数据还是在缓存中查询数据,在application.yml 中将mybatis 对应的mapper 包日志设置为debug . spring: dat ...

  4. 本月16日SpringBoot2.2发布,有哪些变化先知晓

    本月(2019年10月16日)Spring Boot 2.2已经正式发布了!在此篇文章中,将给大家介绍一下2.2版为大家带来了哪些重要的新变化.笔者用心书写,希望阅读完成之后转发关注,你的支持是我不竭 ...

  5. spring boot 1.x.x 到 spring boot 2.x.x 的那些变化

    spring boot1 到 spring boot2的配置变化很大,迁移项目到spring boot2过程中发现以下变化 1.java 的 redis 配置添加了属性jedis 旧版 spring: ...

  6. Springboot2新特性概述

    官方说明: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Release-Notes 起码 JDK 8 和支持 ...

  7. springboot2.0.3源码篇 - 自动配置的实现,发现也不是那么复杂

    前言 开心一刻 女儿: “妈妈,你这么漂亮,当年怎么嫁给了爸爸呢?” 妈妈: “当年你爸不是穷嘛!‘ 女儿: “穷你还嫁给他!” 妈妈: “那时候刚刚毕业参加工作,领导对我说,他是我的扶贫对象,我年轻 ...

  8. springBoot2.0+redis+fastJson+自定义注解实现方法上添加过期时间

    springBoot2.0集成redis实例 一.首先引入项目依赖的maven jar包,主要包括 spring-boot-starter-data-redis包,这个再springBoot2.0之前 ...

  9. RedisCacheManager设置Value序列化器技巧

    CacheManager基本配置 请参考博文:springboot2.0 redis EnableCaching的配置和使用 RedisCacheManager构造函数 /** * Construct ...

随机推荐

  1. Firefox下载附件乱码的解决办法

    通过在http的header里设置fileName下载附件时,中文文件名通过chrome浏览器下载时正常,通过firefox下载时为乱码: 原来的Java代码: response.addHeader( ...

  2. 闪付卡(QuickPass)隐私泄露原理

    0×00 前言 说到闪付卡,首先要从EMV开始,EMV是由Europay,MasterCard和VISA制定的基于IC卡的支付标准规范.目前基于EMV卡的非接触式支付的实现有三个:VISA的payWa ...

  3. 继承 in her it

    ''' in her it 继承 de rive 派生 python2 (经典类|新式类) python3 (新式类) 1. What is inheritance? 什么是继承? 继承是一种新建类的 ...

  4. Representations of graphs

    We can choose between two standard ways to represent a graph as a collection of adjacency lists or a ...

  5. BT详解

    bittorrent是一个文件分发协议,它使用url来定位文件而且跟web服务无缝集成.当有多个人同时下载同一个文件时,下载者之间可以互相上传自己已有的那部分文件,让一个文件支持很多人同时下载却只增加 ...

  6. C\C++控制台程序隐藏方法总结

    学习计算机,往往先从Windows环境下学习编程,学习编程,往往从C学起,学习C,往往又从控制台程序学习,何为控制台,就是那个黑框白字的界面.对于这样一个最初认为奇陋无比而现在认为无所不能的编程平台, ...

  7. 路径定义前+r

    定义文件路径时前面加个r 例如 firstfolder = r"C:\Users\1261\Desktop\" 不对其中的符号进行转义

  8. 在vue.js 中使用animate.css库

    main.js文件引入后,在vue文件里直接添加class   animated bounceInUp

  9. 从零开始写自己的PHP框架系列教程(一)[core.php]

    这里我直接上代码: /** * 框架核心 */ if (version_compare(PHP_VERSION, '5.3.0','<')) { header("Content-Typ ...

  10. java的AES对称加密和解密,有偏移量

    import java.math.BigDecimal; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; i ...