# redis-cache-self-refresh-boot-starter **Repository Path**: damagez/redis-cache-self-refresh-boot-starter ## Basic Information - **Project Name**: redis-cache-self-refresh-boot-starter - **Description**: redis缓存自动刷新工具 - **Primary Language**: Java - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-02-26 - **Last Updated**: 2023-05-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # redis-cache-self-refresh-boot-starter redis缓存自动刷新工具 redis缓存在距离过期的一段时间之前,如果被调用超过N次,则下次调用重新调用方法刷新缓存。 ## 准备 1.拉取代码并install到本地仓库 2.在pom.xml中引入依赖 ```xml com.damagez redis-cache-self-refresh-boot-starter 1.0.0 ``` 进行spring boot redis的配置,例如 ```yaml spring: redis: password: mypassword database: 0 host: 172.0.0.1 timeout: 30s lettuce: pool: max-active: 8 max-wait: 30s max-idle: 8 min-idle: 0 ``` ## 使用方式 使用注解**@RefreshCacheable** 缓存名字的分割符为# 例如:result#3m#30s#5,3m表示缓存的过期时间为3分钟,30s表示缓存距离失效时间前30s内,5表示至少调用5次缓存 在缓存距离失效前30s内,如果缓存调用次数超过5次,则再次调用会触发更新缓存的操作 定义缓存过期时间和缓存距离失效时间需要使用{@link StringToDurationConverter}所指定的语法。 与spring boot的yml文件中指定时间的用法相同 ```java @RefreshCacheable(cacheNames = "myhello#1m#40s#5") @GetMapping("/hello") public String hello(){ System.out.println("方法执行"); return "hello world!"; } ``` 如果不指定至少调用次数,默认的至少调用次数为10次 ```java @RefreshCacheable(cacheNames = "myhello#1m#40s") @GetMapping("/hello") public String hello(){ System.out.println("方法执行"); return "hello world!"; } ```