缓存工具 CacheUtils 增加 computeIfAbsent 简化方法
This commit is contained in:
@@ -28,8 +28,7 @@ public class CacheChatMemoryRepository implements ChatMemoryRepository {
|
||||
|
||||
@Override
|
||||
public @NotNull List<Message> findByConversationId(@NotNull String conversationId) {
|
||||
List<Message> all = CacheUtils.get(CMS_CHAT_MSG_CACHE, conversationId);
|
||||
return all != null ? all : List.of();
|
||||
return CacheUtils.computeIfAbsent(CMS_CHAT_MSG_CACHE, conversationId, k -> List.of());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -85,11 +85,7 @@ public class CmsAiChatService extends BaseService {
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Object>> getChatCacheMap() {
|
||||
Map<String, Map<String, Object>> cache = CacheUtils.get(CMS_CHAT_CACHE, getChatCacheKey());
|
||||
if (cache == null) {
|
||||
cache = MapUtils.newHashMap();
|
||||
}
|
||||
return cache;
|
||||
return CacheUtils.computeIfAbsent(CMS_CHAT_CACHE, getChatCacheKey(), k -> MapUtils.newHashMap());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user