From b2012f9209f88e53424765b8063a21b6985d63dd Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Fri, 13 Feb 2026 12:07:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(cache):=20=E6=B7=BB=E5=8A=A0=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=B8=85=E7=90=86=E5=8A=9F=E8=83=BD=E4=BB=A5=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=95=B0=E6=8D=AE=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在设备默认配置的创建、更新和删除操作后清理相关缓存 - 在设备信息更新和删除操作后清理设备缓存 - 在分账规则的更新、删除、启用和禁用操作后清理规则缓存 - 实现了针对特定配置键的缓存清理方法 - 实现了清除所有默认配置缓存的方法 - 实现了针对特定规则ID的缓存清理方法 --- ...DeviceDefaultConfigIntegrationService.java | 28 ++++++++++++++++++- .../service/DeviceIntegrationService.java | 4 +++ .../ProfitShareIntegrationService.java | 18 +++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java b/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java index 97ba52a9..1ad2d521 100644 --- a/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/device/service/DeviceDefaultConfigIntegrationService.java @@ -64,6 +64,8 @@ public class DeviceDefaultConfigIntegrationService { log.info("创建默认配置, configKey: {}", request.getConfigKey()); CommonResponse response = defaultConfigClient.createDefaultConfig(request); String result = handleResponse(response, "创建默认配置失败"); + // 清理相关缓存 + clearDefaultConfigCache(request.getConfigKey()); return result != null; } @@ -75,6 +77,9 @@ public class DeviceDefaultConfigIntegrationService { CommonResponse> response = defaultConfigClient.updateDefaultConfig(configKey, updates); Map result = handleResponse(response, "更新默认配置失败"); + // 清理相关缓存 + clearDefaultConfigCache(configKey); + // 检查是否有冲突信息 if (result != null && result.containsKey("conflict")) { Object conflictObj = result.get("conflict"); @@ -94,6 +99,8 @@ public class DeviceDefaultConfigIntegrationService { log.info("删除默认配置, configKey: {}", configKey); CommonResponse response = defaultConfigClient.deleteDefaultConfig(configKey); String result = handleResponse(response, "删除默认配置失败"); + // 清理相关缓存 + clearDefaultConfigCache(configKey); return result != null; } @@ -103,7 +110,26 @@ public class DeviceDefaultConfigIntegrationService { public BatchDefaultConfigResponse batchUpdateDefaultConfigs(BatchDefaultConfigRequest request) { log.info("批量更新默认配置, configs count: {}", request.getConfigs().size()); CommonResponse response = defaultConfigClient.batchUpdateDefaultConfigs(request); - return handleResponse(response, "批量更新默认配置失败"); + BatchDefaultConfigResponse result = handleResponse(response, "批量更新默认配置失败"); + // 清理所有默认配置相关缓存 + clearAllDefaultConfigCache(); + return result; + } + + /** + * 清理指定配置的缓存 + */ + private void clearDefaultConfigCache(String configKey) { + if (configKey != null) { + fallbackService.clearFallbackCache(SERVICE_NAME, "defaults:config:" + configKey); + } + } + + /** + * 清理所有默认配置缓存 + */ + private void clearAllDefaultConfigCache() { + fallbackService.clearAllFallbackCache(SERVICE_NAME); } /** diff --git a/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java b/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java index 0790b520..67e1b51d 100644 --- a/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/device/service/DeviceIntegrationService.java @@ -58,12 +58,16 @@ public class DeviceIntegrationService { log.debug("更新设备信息, deviceId: {}", deviceId); CommonResponse response = deviceV2Client.updateDevice(deviceId, request); handleResponse(response, "更新设备信息失败"); + // 清理设备相关缓存 + fallbackService.clearFallbackCache(SERVICE_NAME, "device:" + deviceId); } public void deleteDevice(Long deviceId) { log.debug("删除设备, deviceId: {}", deviceId); CommonResponse response = deviceV2Client.deleteDevice(deviceId); handleResponse(response, "删除设备失败"); + // 清理设备相关缓存 + fallbackService.clearFallbackCache(SERVICE_NAME, "device:" + deviceId); } public PageResponse listDevices(Integer page, Integer pageSize, String name, String no, diff --git a/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java b/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java index 40a2347d..c9940579 100644 --- a/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java +++ b/src/main/java/com/ycwl/basic/integration/profitshare/service/ProfitShareIntegrationService.java @@ -83,7 +83,10 @@ public class ProfitShareIntegrationService { public RuleVO updateRule(Long ruleId, CreateRuleRequest request) { log.debug("更新分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.updateRule(ruleId, request); - return handleResponse(response, "更新分账规则失败"); + RuleVO result = handleResponse(response, "更新分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); + return result; } /** @@ -93,6 +96,8 @@ public class ProfitShareIntegrationService { log.debug("删除分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.deleteRule(ruleId); handleResponse(response, "删除分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); } /** @@ -102,6 +107,8 @@ public class ProfitShareIntegrationService { log.debug("启用分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.enableRule(ruleId); handleResponse(response, "启用分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); } /** @@ -111,6 +118,8 @@ public class ProfitShareIntegrationService { log.debug("禁用分账规则, ruleId: {}", ruleId); CommonResponse response = profitShareClient.disableRule(ruleId); handleResponse(response, "禁用分账规则失败"); + // 清理规则缓存 + clearRuleCache(ruleId); } // ==================== 分账记录查询 ==================== @@ -211,6 +220,13 @@ public class ProfitShareIntegrationService { // ==================== 私有方法 ==================== + /** + * 清理规则相关缓存 + */ + private void clearRuleCache(Long ruleId) { + fallbackService.clearFallbackCache(SERVICE_NAME, "rule:" + ruleId); + } + private T handleResponse(CommonResponse response, String errorMessage) { if (response == null || !response.isSuccess()) { String msg = response != null && response.getMessage() != null