feat(scenic): 添加景区配置和服务缓存清理功能

- 在创建配置后清理配置列表缓存
- 在更新配置后清理配置相关缓存
- 在删除配置后清理整个列表缓存
- 在批量更新配置后清理所有相关缓存
- 在更新景区信息后清理单个景区缓存
- 在删除景区后清理对应缓存
- 添加清除指定配置缓存的私有方法
- 添加清除景区所有配置缓存的私有方法
This commit is contained in:
2026-02-13 12:06:04 +08:00
parent 78c45343d6
commit 1f302aefd6
2 changed files with 37 additions and 4 deletions

View File

@@ -55,25 +55,53 @@ public class ScenicConfigIntegrationService {
public ScenicConfigV2DTO createConfig(Long scenicId, CreateConfigRequest request) {
log.debug("创建景区配置, scenicId: {}, configKey: {}", scenicId, request.getConfigKey());
CommonResponse<ScenicConfigV2DTO> response = scenicConfigV2Client.createConfig(scenicId, request);
return handleResponse(response, "创建景区配置失败");
ScenicConfigV2DTO result = handleResponse(response, "创建景区配置失败");
// 清理配置列表缓存
clearConfigCache(scenicId, request.getConfigKey());
return result;
}
public ScenicConfigV2DTO updateConfig(Long scenicId, String id, UpdateConfigRequest request) {
log.debug("更新景区配置, scenicId: {}, id: {}", scenicId, id);
CommonResponse<ScenicConfigV2DTO> response = scenicConfigV2Client.updateConfig(scenicId, id, request);
return handleResponse(response, "更新景区配置失败");
ScenicConfigV2DTO result = handleResponse(response, "更新景区配置失败");
// 清理配置相关缓存
clearConfigCache(scenicId, request.getConfigKey());
return result;
}
public void deleteConfig(Long scenicId, String id) {
log.debug("删除景区配置, scenicId: {}, id: {}", scenicId, id);
CommonResponse<Void> response = scenicConfigV2Client.deleteConfig(scenicId, id);
handleResponse(response, "删除景区配置失败");
// 清理配置列表缓存(无法确定具体key,清理整个列表缓存)
fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:configs:" + scenicId);
}
public BatchUpdateResponse batchUpdateConfigs(Long scenicId, BatchConfigRequest request) {
log.debug("批量更新景区配置, scenicId: {}, configs count: {}", scenicId, request.getConfigs().size());
CommonResponse<BatchUpdateResponse> response = scenicConfigV2Client.batchUpdateConfigs(scenicId, request);
return handleResponse(response, "批量更新景区配置失败");
BatchUpdateResponse result = handleResponse(response, "批量更新景区配置失败");
// 清理所有相关缓存
clearAllConfigCache(scenicId);
return result;
}
/**
* 清理指定配置的缓存
*/
private void clearConfigCache(Long scenicId, String configKey) {
fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:configs:" + scenicId);
if (configKey != null) {
fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:config:" + scenicId + ":" + configKey);
}
}
/**
* 清理景区所有配置相关缓存
*/
private void clearAllConfigCache(Long scenicId) {
fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:configs:" + scenicId);
}

View File

@@ -48,13 +48,18 @@ public class ScenicIntegrationService {
public ScenicV2DTO updateScenic(Long scenicId, UpdateScenicRequest request) {
log.debug("更新景区信息, scenicId: {}", scenicId);
CommonResponse<ScenicV2DTO> response = scenicV2Client.updateScenic(scenicId, request);
return handleResponse(response, "更新景区信息失败");
ScenicV2DTO result = handleResponse(response, "更新景区信息失败");
// 清理缓存,确保下次查询获取最新数据
fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:" + scenicId);
return result;
}
public void deleteScenic(Long scenicId) {
log.debug("删除景区, scenicId: {}", scenicId);
CommonResponse<Void> response = scenicV2Client.deleteScenic(scenicId);
handleResponse(response, "删除景区失败");
// 清理缓存
fallbackService.clearFallbackCache(SERVICE_NAME, "scenic:" + scenicId);
}
public ScenicFilterPageResponse filterScenics(ScenicFilterRequest request) {