Skip to content

Commit fdb6fb3

Browse files
committed
feat: 添加一个 security cache manager,过期时间设置为 jwt 配置
1 parent d7a9d85 commit fdb6fb3

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package top.cadecode.framework.config;
2+
3+
import com.github.benmanes.caffeine.cache.Caffeine;
4+
import lombok.RequiredArgsConstructor;
5+
import org.springframework.cache.CacheManager;
6+
import org.springframework.cache.annotation.EnableCaching;
7+
import org.springframework.cache.caffeine.CaffeineCacheManager;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import top.cadecode.common.util.TokenUtil;
11+
12+
import java.util.concurrent.TimeUnit;
13+
14+
/**
15+
* @author Cade Li
16+
* @date 2022/1/5
17+
* @description SpringBoot Cache 配置类
18+
*/
19+
@RequiredArgsConstructor
20+
@Configuration
21+
@EnableCaching
22+
public class CacheConfig {
23+
24+
private final TokenUtil tokenUtil;
25+
26+
@Bean("securityCacheManager")
27+
public CacheManager securityCacheManager() {
28+
CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager();
29+
// 更新时间设置为 jwt token 配置时间
30+
caffeineCacheManager.setCaffeine(Caffeine.newBuilder()
31+
.expireAfterWrite(tokenUtil.getExpiration(), TimeUnit.SECONDS));
32+
caffeineCacheManager.setAllowNullValues(true);
33+
return caffeineCacheManager;
34+
}
35+
}

0 commit comments

Comments
 (0)