2018-01-17 14:10:40 +08:00
|
|
|
package cn.keking.utils;
|
|
|
|
|
|
2019-04-16 21:09:32 +08:00
|
|
|
import cn.keking.config.ConfigConstants;
|
2019-06-11 09:53:39 +08:00
|
|
|
import cn.keking.service.cache.CacheService;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
2018-01-17 14:10:40 +08:00
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
2019-06-11 09:53:39 +08:00
|
|
|
/**
|
|
|
|
|
* @auther: chenjh
|
|
|
|
|
* @since: 2019/6/11 7:45
|
|
|
|
|
*/
|
2018-01-17 14:10:40 +08:00
|
|
|
@Component
|
2019-06-11 09:53:39 +08:00
|
|
|
@ConditionalOnExpression("'${cache.clean:false}'.equals('true')")
|
2018-01-17 14:10:40 +08:00
|
|
|
public class ShedulerClean {
|
|
|
|
|
|
2019-06-11 09:53:39 +08:00
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ShedulerClean.class);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
|
|
|
|
private String fileDir = ConfigConstants.getFileDir();
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 0 3 * * ?") //每晚3点执行一次
|
|
|
|
|
public void clean() {
|
|
|
|
|
LOGGER.info("Cache clean start");
|
|
|
|
|
cacheService.cleanCache();
|
2018-01-17 14:10:40 +08:00
|
|
|
DeleteFileUtil.deleteDirectory(fileDir);
|
2019-06-11 09:53:39 +08:00
|
|
|
LOGGER.info("Cache clean end");
|
2018-01-17 14:10:40 +08:00
|
|
|
}
|
|
|
|
|
}
|