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. mssql server 数据库帮助类

    using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Web ...

  2. DWZ 在js中刷新某个navTab

    当时的想法是: 上传一个文件成功后 刷新navTab ,关闭上传文件dialog. function fileNameBack(args){ //表单毁掉函数 alertMsg.correct(arg ...

  3. ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一)

    前言: 第一次接触ABP的项目是在2018年6月份,但是当时没有深入具体的研究,而今天因为工作的需要,需要学习.了解这个框架,在时隔半年之后,今天重新下载了这个项目,虽然在园子里有很多前辈们写的这类的 ...

  4. Java程序员从阿里面试回来,这些面试题你们会吗?

    前不久刚从阿里面试回来,为了这场面试可以说准备了一个半月,做的准备就是刷题和看视频看书充实自己的技术,话说是真难啊,不过还算顺利拿到了offer,有很多面试题我已经记不起来了,这些是当天回家整理好的, ...

  5. 【linux】State : Uninterruptible, pid: 3936

    运行centos7中yum命令时提示: Existing lock /var/run/yum.pid: another copy is running as pid 3936.Another app ...

  6. 小伙 zwfw-new.hunan.gov.cn.iname.damddos.com [222.240.80.52]

    由于这个应用出问题非常影响用户体验:于是立马让运维保留现场 dump 线程和内存同时重启应用,还好重启之后恢复正常.于是开始着手排查问题.

  7. 小程序 movable-area 实现悬浮窗效果

    最近做一个小程序 实现页面内悬浮窗的效果 给自己制定两个方案: 1.通过一个自定义的组件,通过触摸事件进行实现: 2.使用微信的movable移动组件实现: 第一种方案: 结果:实现了 悬浮窗和自动靠 ...

  8. Heap Sort - recursion

    Heap Sort  Build a max heap using exsiting array, which is called Heapify Swap root with the last el ...

  9. webpack根据开发与生产环境配置不同变量--webpack.DefinePlugin

    webpack有一个DefinePlugin接口,可以实现根据开发与生产环境配置不同变量.范例如下: 需求:开发环境请求baseUrl = '':生产环境请求 baseUrl = 'http://lo ...

  10. Error: “app_name” is not translated in af

    in values/strings.xml   "app_name" is not translated in af, am, ar, be, bg, ca, cs, da, de ...