shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.iplatform.base.cache;
 
import com.iplatform.base.Constants;
import com.iplatform.base.WechatCacheProvider;
import com.iplatform.base.WechatConstants;
import com.walker.support.redis.cache.RedisCacheProvider;
 
/**
 * 微信相关缓存,由于存在票据、token等过期设置,因此测试也需要使用Redis方式。
 * @author 时克英
 * @date 2023-07-16
 */
public class RedisWechatCache extends RedisCacheProvider<String> implements WechatCacheProvider {
 
    public RedisWechatCache(){
        this.setUseRedis(true);
        this.setLoadPage(false);
        // 2024-01-05 设置支持缓存失效,该参数很重要,如果需要失效而没有设置在调用后会出现数据无法失效!
        this.setSupportExpiredCache(true);
    }
 
    @Override
    public String getMiniAccessToken() {
        return this.getCacheData(WechatConstants.REDIS_WECAHT_MINI_ACCESS_TOKEN_KEY);
    }
 
    @Override
    public String getJsApiTicket() {
        return this.getCacheData(WechatConstants.REDIS_PUBLIC_JS_API_TICKET);
    }
 
    @Override
    public String getPublicAccessToken() {
        return this.getCacheData(WechatConstants.REDIS_WECAHT_PUBLIC_ACCESS_TOKEN_KEY);
    }
 
    @Override
    public void putPublicAccessToken(String value, long expiredSeconds) {
        this.putCacheData(WechatConstants.REDIS_WECAHT_PUBLIC_ACCESS_TOKEN_KEY, value, expiredSeconds);
    }
 
    @Override
    public void putJsApiTicket(String value) {
        this.putCacheData(WechatConstants.REDIS_PUBLIC_JS_API_TICKET, value, WechatConstants.REDIS_PUBLIC_JS_API_TICKET_EXPRESS);
    }
 
    @Override
    public void putMiniAccessToken(String value, long expiredSeconds) {
        this.putCacheData(WechatConstants.REDIS_WECAHT_MINI_ACCESS_TOKEN_KEY, value, expiredSeconds);
    }
 
    @Override
    public void removeMiniAccessToken() {
        this.removeCacheData(WechatConstants.REDIS_WECAHT_MINI_ACCESS_TOKEN_KEY);
    }
 
    @Override
    public String getProviderName() {
        return Constants.CACHE_NAME_WECHAT;
    }
 
    @Override
    public Class<?> getProviderType() {
        return String.class;
    }
}