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. Sharepoint 2016 配置FBA(一) 创建Membership数据库

    在Sharepoint 2016上配置FBA(forms based authentication)的过程和Sharepoint 2013一样. 第一步:创建Membership数据库. 为了存放所有 ...

  2. key单片机按键抖动

    //write by:cyt //Time:2017-2-10 //Porject Name:key shake_destory #include<reg51.h> #define GPI ...

  3. failed to start process with commandline '%LAUNCHER_PATH% %LAUNCHER_ARGS%', ErrorCode = '0x80070002

    在dotnet core进行开发的时候,需要开发目录直接iis进行部署,然而启动的时候,报异常,我们查看windows下的应用日志发现有个这样的错误信息 Application 'MACHINE/WE ...

  4. Element-ui 更新tableData 中 row的某一个属性时,没有更新视图的问题

    在一个报警音管理的页面中,每次点击试听的时候,需要把‘试听’ 更新为 ‘停止’, 起初我们给row.play=0时,显示为 试听,row.play=1时显示为停止, 但是在代码中每次为row.play ...

  5. caog

    import pandas as pd#匹配可发库存1. import oslst=os.listdir(r'E:\每日必做\琪琪小象库存')lst1=[]for i in lst: if i[:2] ...

  6. php $_FILES错误说明 以及图片前端图片上传失败。

    我的另一个原文:https://blog.csdn.net/qq_36570464/article/details/80692241 今天被一个问题弄了好久, 先看代码: 前端: <form m ...

  7. react native 0.50与OC交互 && Swift与RN交互

    新公司也打算做rn,还是得捡起来再度学习.开撸! react native一个版本一个样子,之前写的rn与iOS交互系列在最新版本中有点出入(0.50.4版本).今天填一下坑. 首先上npm版本,re ...

  8. redis客户端(三)

    redis客户端 一.>redis自带的客户端 启动 启动客户端命令:[root@ming bin]# ./redis-cli -h xxx.xxx.xx.xxx-p 6379 注意: -h:指 ...

  9. svn 部署

    安装svn [root@localhost ~]# yum -y install subversion 创建两个目录 一个 数据存储 一个用户密码 [root@localhost ~]# mkdir ...

  10. urllib.error.URLError: <urlopen error [WinError 10061] 由于目标计算机积极拒绝,无法连接。>

    因为昨天我用fiddler抓包实验它的基本功能,今天运行程序时没有打开fiddler,所以配置的代理失效了,返回这样的错误. 这个问题是因为代理设置失效,换一个代理或者取消设置代理即可.