🐛 修复更改策略时, 未正确启用和关闭缓存的 BUG

This commit is contained in:
zhaojun1998
2020-01-12 11:14:20 +08:00
parent f6c5f7a91b
commit 594246127d
2 changed files with 7 additions and 6 deletions

View File

@@ -60,6 +60,7 @@ public class AdminController {
systemConfigService.updateSystemConfig(systemConfigDTO);
if (!Objects.equals(currentStorageStrategy, systemConfigDTO.getStorageStrategy())) {
log.info("已将存储策略由 {} 切换为 {}", currentStorageStrategy, systemConfigDTO.getStorageStrategy());
refreshStorageStrategy();
}
@@ -136,9 +137,8 @@ public class AdminController {
} else {
AbstractFileService fileService = systemConfigService.getCurrentFileService();
fileService.init();
log.info("当前启用存储类型: {}", storageStrategy.getDescription());
log.info("切换至存储类型: {}", storageStrategy.getDescription());
// if 判断是否开启搜索.
fileAsyncCacheService.cacheGlobalFile();
}
}

View File

@@ -14,7 +14,6 @@ import im.zhaojun.common.model.enums.StorageTypeEnum;
import im.zhaojun.common.repository.SystemConfigRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.lang.reflect.Field;
@@ -41,6 +40,9 @@ public class SystemConfigService {
@Resource
private FileAsyncCacheService fileAsyncCacheService;
@Resource
private FileCacheService fileCacheService;
private Class<SystemConfigDTO> systemConfigDTOClass = SystemConfigDTO.class;
public SystemConfigDTO getSystemConfig() {
@@ -103,13 +105,12 @@ public class SystemConfigService {
if (!oldEnableCache && curEnableCache) {
log.debug("检测到开启了缓存, 开启预热缓存");
currentFileService.openCacheAutoRefresh();
fileAsyncCacheService.cacheGlobalFile();
fileCacheService.enableCache();
}
if (oldEnableCache && !curEnableCache) {
log.debug("检测到关闭了缓存, 正在清理缓存数据及关闭自动刷新");
currentFileService.clearFileCache();
fileCacheService.disableCache();
}
}