perf(oa): 调整 AI 相关缓存策略- 将 AI 回复的缓存时间从 5 分钟调整为 1 天
- 将 AI 配置的缓存时间从 30 分钟调整为 1 天 - 将对话历史的缓存时间从 10 分钟调整为 1 天 这些调整旨在减少频繁调用 AI 接口导致的 token 消耗,并提升系统响应速度。
This commit is contained in:
@@ -115,7 +115,7 @@ public class AiServiceUtil {
|
||||
int totalTokens = jsonNode.path("usage").path("total_tokens").asInt();
|
||||
log.info("AI回复成功,消耗token: {}", totalTokens);
|
||||
|
||||
// 9. 缓存AI回复(缓存5分钟)
|
||||
// 9. 缓存AI回复(缓存一天)
|
||||
RedisUtils.setCacheObject(cacheKey, aiResponse, Duration.ofDays(1));
|
||||
|
||||
return aiResponse;
|
||||
@@ -143,8 +143,8 @@ public class AiServiceUtil {
|
||||
// 缓存中没有,从数据库获取
|
||||
SysOaAiConfigVo config = configService.getActiveConfig();
|
||||
if (config != null) {
|
||||
// 缓存配置(缓存30分钟)
|
||||
RedisUtils.setCacheObject(AI_CONFIG_CACHE_KEY, config, Duration.ofMinutes(30));
|
||||
// 缓存配置(缓存一天)
|
||||
RedisUtils.setCacheObject(AI_CONFIG_CACHE_KEY, config, Duration.ofDays(1));
|
||||
log.debug("AI配置已缓存到Redis");
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class AiServiceUtil {
|
||||
*/
|
||||
public void cacheConversationHistory(Long conversationId, List<SysOaAiMessageVo> messages) {
|
||||
String cacheKey = AI_CONVERSATION_CACHE_KEY + conversationId;
|
||||
RedisUtils.setCacheObject(cacheKey, messages, Duration.ofMinutes(10));
|
||||
RedisUtils.setCacheObject(cacheKey, messages, Duration.ofDays(1));
|
||||
log.debug("对话历史已缓存到Redis, conversationId: {}", conversationId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user