From bc3110e708f0f1b8ecb260f191ec80edffa703ad Mon Sep 17 00:00:00 2001 From: sol Date: Thu, 26 Jun 2025 10:12:46 +0800 Subject: [PATCH] feat(service): Refactored the "cacheSearch" method --- .../common/core/base/service/BaseService.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java b/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java index 05fc629..c66f187 100644 --- a/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java +++ b/cloud/common/common-base-web/src/main/java/com/bgasol/common/core/base/service/BaseService.java @@ -436,24 +436,24 @@ public abstract class BaseService mapCache = getRMapCache(); - if (mapCache.containsKey(id)) { - ENTITY entity = mapCache.get(id); - if (entity.getId().equals(NULL_PLACEHOLDER)) { + ENTITY entity = mapCache.get(id); + + if (entity != null) { + if (NULL_PLACEHOLDER.equals(entity.getId())) { return null; - } else { - return entity; - } - } else { - ENTITY entity = commonBaseMapper().selectById(id); - // 如果是null就存储一个id为"null"的字符串做标记 防止穿透 - if (entity == null) { - mapCache.put(id, (ENTITY) BaseEntity.builder().id(NULL_PLACEHOLDER).build(), randomizeTtl(), DEFAULT_TIME_UNIT); - } else { - mapCache.put(id, entity, randomizeTtl(), DEFAULT_TIME_UNIT); } return entity; } + + entity = commonBaseMapper().selectById(id); + if (entity == null) { + mapCache.put(id, (ENTITY) BaseEntity.builder().id(NULL_PLACEHOLDER).build(), randomizeTtl(), DEFAULT_TIME_UNIT); + } else { + mapCache.put(id, entity, randomizeTtl(), DEFAULT_TIME_UNIT); + } + return entity; } /**