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

springboot 使用注解设置缓存时效

springboot 使用注解设置缓存时效

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;import java.time.Duration;public class CustomRedisCacheManager extends RedisCacheManager {/** @description 提供默认构造器* @author xianping* @date 2020/9/28 9:22* @param* @param cacheWriter* @param defaultCacheConfiguration* @return**/public CustomRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {super(cacheWriter, defaultCacheConfiguration);}/** @description 重写父类createRedisCache方法* @author xianping* @date 2020/9/28 9:22* @param* @param name @Cacheable中的value* @param cacheConfig* @return org.springframework.data.redis.cache.RedisCache**/@Overrideprotected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {//名称中存在#标记进行到期时间配置if (!name.isEmpty() && name.contains("#")) {String[] SPEL = name.split("#");if (StringUtils.isNumeric(SPEL[1])) {//配置缓存到期时间int cycle = Integer.parseInt(SPEL[1]);return super.createRedisCache(SPEL[0], cacheConfig.entryTtl(Duration.ofMinutes(cycle * 24 * 60)));}}return super.createRedisCache(name, cacheConfig);}
}
 @PostMapping("/getVehicleMap")@Cacheable(value = "getVehicle#1")@Operation(summary = "交通工具类型获取")public R<JSONArray> getVehicleMap() {
http://www.lryc.cn/news/510605.html

相关文章:

  • QGIS二次开发(地图符号库操作)
  • 线性代数行列式
  • Vision Transformer (ViT) 论文的第二句话
  • Github 2024-12-27 Java开源项目日报Top10
  • 气相色谱-质谱联用分析方法中的常用部件,分流平板更换
  • centos7 免安装mysql5.7及配置(支持多个mysql)
  • Python的Pandas--Series的创建和实现
  • OCR实践-问卷表格统计
  • uniapp中的条件编译
  • Segment Routing Overview
  • 【K8s】专题十五(6):Kubernetes 网络之 Pod 网络调试
  • CMake 构建项目并整理头文件和库文件
  • Boost之log日志使用
  • 多功能jquery图片预览放大镜插件
  • CSS系列(39)-- Shapes详解
  • AI 神经网络在智能家居场景中的应用
  • Rocky DEM tutorial7_Conical Dryer_锥形干燥器
  • CSS(二):美化网页元素
  • 平方根无迹卡尔曼滤波(SR-UKF)算法,用于处理三维非线性状态估计问题
  • 【论文笔记】Visual Alignment Pre-training for Sign Language Translation
  • NLP基础知识 - 向量化
  • JAVA学习笔记_MySQL进阶
  • ffmpeg: stream_loop报错 Error while filtering: Operation not permitted
  • Vue.use()和Vue.component()
  • javaweb 04 springmvc
  • [Visual studio] 性能探测器
  • 【漫话机器学习系列】017.大O算法(Big-O Notation)
  • IntelliJ IDEA中设置激活的profile
  • Qt 的信号槽机制详解:之信号槽引发的 Segmentation Fault 问题拆析(上)
  • uniapp中实现APP调用本地通知栏通知、震动、本地提示音或者mp3提醒