File tree Expand file tree Collapse file tree
simple-framework/src/main/java/top/cadecode/framework/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments