From ac5e2102691e0303bba9c7ec191f3d9932e5334d Mon Sep 17 00:00:00 2001 From: wuzongyong <13203449218@163.com> Date: Fri, 16 Jan 2026 09:23:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(databus):=20=E7=A7=BB=E9=99=A4API?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=87=AD=E8=AF=81=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E7=BC=93=E5=AD=98=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了基于Caffeine的凭证缓存逻辑 - 移除了PostConstruct注解的缓存初始化方法 - 删除了缓存相关的成员变量和配置 - 移除了所有缓存失效操作包括创建、更新和删除时的缓存清理 - 简化了凭证查询逻辑直接通过数据库访问 - 保留了核心的API凭证管理功能和匿名用户服务集成 --- .../impl/ApiClientCredentialServiceImpl.java | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/service/gateway/impl/ApiClientCredentialServiceImpl.java b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/service/gateway/impl/ApiClientCredentialServiceImpl.java index 415684fb..6f2f580a 100644 --- a/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/service/gateway/impl/ApiClientCredentialServiceImpl.java +++ b/zt-module-databus/zt-module-databus-server/src/main/java/com/zt/plat/module/databus/service/gateway/impl/ApiClientCredentialServiceImpl.java @@ -1,7 +1,5 @@ package com.zt.plat.module.databus.service.gateway.impl; -import com.github.benmanes.caffeine.cache.Caffeine; -import com.github.benmanes.caffeine.cache.LoadingCache; import com.zt.plat.framework.common.exception.util.ServiceExceptionUtil; import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.util.object.BeanUtils; @@ -11,14 +9,12 @@ import com.zt.plat.module.databus.dal.dataobject.gateway.ApiClientCredentialDO; import com.zt.plat.module.databus.dal.mysql.gateway.ApiClientCredentialMapper; import com.zt.plat.module.databus.service.gateway.ApiAnonymousUserService; import com.zt.plat.module.databus.service.gateway.ApiClientCredentialService; -import jakarta.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; -import java.time.Duration; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -36,16 +32,6 @@ public class ApiClientCredentialServiceImpl implements ApiClientCredentialServic private final ApiClientCredentialMapper credentialMapper; private final ApiAnonymousUserService anonymousUserService; - private LoadingCache> credentialCache; - - @PostConstruct - public void initCache() { - credentialCache = Caffeine.newBuilder() - .maximumSize(256) - .expireAfterWrite(Duration.ofMinutes(5)) - .build(this::loadCredentialSync); - } - @Override public PageResult getPage(ApiClientCredentialPageReqVO reqVO) { return credentialMapper.selectPage(reqVO); @@ -67,7 +53,6 @@ public class ApiClientCredentialServiceImpl implements ApiClientCredentialServic credential.setAnonymousUserId(null); } credentialMapper.insert(credential); - invalidateCache(credential.getAppId()); return credential.getId(); } @@ -86,8 +71,6 @@ public class ApiClientCredentialServiceImpl implements ApiClientCredentialServic updateObj.setAnonymousUserId(null); } credentialMapper.updateById(updateObj); - invalidateCache(existing.getAppId()); - invalidateCache(updateObj.getAppId()); if (!Objects.equals(existing.getAnonymousUserId(), updateObj.getAnonymousUserId())) { anonymousUserService.invalidate(existing.getAnonymousUserId()); anonymousUserService.invalidate(updateObj.getAnonymousUserId()); @@ -99,7 +82,6 @@ public class ApiClientCredentialServiceImpl implements ApiClientCredentialServic public void delete(Long id) { ApiClientCredentialDO existing = ensureExists(id); credentialMapper.deleteById(id); - invalidateCache(existing.getAppId()); anonymousUserService.invalidate(existing.getAnonymousUserId()); } @@ -118,11 +100,7 @@ public class ApiClientCredentialServiceImpl implements ApiClientCredentialServic if (!StringUtils.hasText(appId)) { return Optional.empty(); } - return credentialCache.get(appId.trim()); - } - - private Optional loadCredentialSync(String appId) { - Optional credential = credentialMapper.selectByAppId(appId) + Optional credential = credentialMapper.selectByAppId(appId.trim()) .filter(item -> Boolean.TRUE.equals(item.getEnabled())); if (credential.isEmpty()) { log.debug("[API-PORTAL] 未找到 appId={} 的有效凭证", appId); @@ -147,13 +125,6 @@ public class ApiClientCredentialServiceImpl implements ApiClientCredentialServic return credential; } - private void invalidateCache(String appId) { - if (!StringUtils.hasText(appId)) { - return; - } - credentialCache.invalidate(appId.trim()); - } - private void normalizeAnonymousSettings(ApiClientCredentialSaveReqVO reqVO) { if (Boolean.TRUE.equals(reqVO.getAllowAnonymous())) { if (reqVO.getAnonymousUserId() == null) {