无关风月
2025-02-14 11ec1c23a9f47ed70b124e413e33e3696897390f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.jilongda.common.config;
 
import com.jilongda.common.cache.Cache;
import com.jilongda.common.cache.CaffineCache;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
import java.util.concurrent.TimeUnit;
 
/**
 * @author xiaochen
 * @ClassName AccessTokenConfig
 * @Description
 * @date 2021-01-02 19:56
 */
@Configuration
public class AccessTokenConfig {
    @Value("${token.env:none}")
    private String env;
    @Value("${token.tokenExpireTime:7200}")
    private long tokenExpireTime;
    @Value("${token.refreshTokenExpireTime:86400}")
    private long refreshTokenExpireTime;
 
    /**
     * 令牌缓存
     *
     * @return
     */
    @Bean
    public CaffineCache<String> accessTokenCache() {
        Cache cache = Cache.options().setDuration(tokenExpireTime).setTimeUnit(TimeUnit.SECONDS).build();
        return new CaffineCache(env, cache);
    }
 
    /**
     * 刷新令牌缓存
     *
     * @return
     */
    @Bean
    public CaffineCache<String> refreshTokenCache() {
        Cache cache = Cache.options().setDuration(refreshTokenExpireTime).setTimeUnit(TimeUnit.SECONDS).build();
        return new CaffineCache(env, cache);
    }
}