package com.agentdriving.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);
|
}
|
|
}
|