修改公共数据类带过期时间
This commit is contained in:
@@ -13,7 +13,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class CommonDataUtil {
|
||||
private static Map<String, Object> token = new HashMap<>();
|
||||
private static final long EXPIRY = 1000 * 60;
|
||||
private static final long MINUTE = 1000 * 60;
|
||||
|
||||
private CommonDataUtil() {
|
||||
}
|
||||
@@ -34,15 +34,15 @@ public class CommonDataUtil {
|
||||
/**
|
||||
* 存数据,带有效期
|
||||
*
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @param invalid 分钟
|
||||
* @param key key
|
||||
* @param value value
|
||||
* @param minute 分钟
|
||||
*/
|
||||
public static void setData(String key, Object value, int invalid) {
|
||||
public static void setData(String key, Object value, int minute) {
|
||||
JSONObject object = new JSONObject();
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
object.put("value", value);
|
||||
object.put("expiry", currentTimeMillis + invalid * EXPIRY);
|
||||
object.put("expiry", currentTimeMillis + minute * MINUTE);
|
||||
token.put(key, object);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xwbing.configuration;
|
||||
|
||||
import com.xwbing.util.CommonDataUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -17,10 +18,9 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
public class SchedulingConfig {
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchedulingConfig.class);
|
||||
|
||||
@Scheduled(cron = "0 */30 * * * ?") // 每半小时执行一次
|
||||
@Scheduled(cron = "0 0 6 * * ? ")//每天6点开启定时任务
|
||||
public void scheduler() {
|
||||
logger.info("scheduled ==================");
|
||||
//TODO
|
||||
logger.info("清除公共数据类过期数据===================");
|
||||
CommonDataUtil.clearExpiryData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user