liujie
2023-08-16 db7fa6a91b9534ac90e219b6f554c54c43c83a5a
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
package com.supersavedriving.driver.modular.system.util.MallBook.util;
 
import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
 
/**
 * @author linqy
 * 缓存工具类,生产建议使用其他缓存中间件
 */
public class CacheUtils {
    private static final TimedCache<String, String> TIMED_CACHE = CacheUtil.newTimedCache(5000);
 
    static {
        /** 每1s检查一次过期 */
        TIMED_CACHE.schedulePrune(1000);
    }
 
    /**
     * 存入键值对,提供消逝时间
     *
     * @param key
     * @param value
     * @param timeout
     */
    public static void put(String key, String value, Long timeout) {
        /** 设置消逝时间 */
        TIMED_CACHE.put(key, value, timeout);
    }
 
    /**
     * 每次重新get一次缓存,均会重新刷新消逝时间
     * @param key
     * @return
     */
    public static String get(String key) {
        return TIMED_CACHE.get(key);
    }
 
}