|
@@ -87,7 +87,7 @@ class TrunksService:
|
|
|
} for r in results]
|
|
|
|
|
|
if conversation_id:
|
|
|
- set_cache(conversation_id, result_list)
|
|
|
+ self.set_cache(conversation_id, result_list)
|
|
|
|
|
|
return result_list
|
|
|
finally:
|
|
@@ -143,19 +143,31 @@ class TrunksService:
|
|
|
finally:
|
|
|
db.close()
|
|
|
|
|
|
+ _cache = {}
|
|
|
+
|
|
|
+ def get_cache(self, conversation_id: str) -> List[dict]:
|
|
|
+ """
|
|
|
+ 根据conversation_id获取缓存结果
|
|
|
+ :param conversation_id: 会话ID
|
|
|
+ :return: 结果列表
|
|
|
+ """
|
|
|
+ return self._cache.get(conversation_id, [])
|
|
|
+
|
|
|
+ def set_cache(self, conversation_id: str, result: List[dict]) -> None:
|
|
|
+ """
|
|
|
+ 设置缓存结果
|
|
|
+ :param conversation_id: 会话ID
|
|
|
+ :param result: 要缓存的结果
|
|
|
+ """
|
|
|
+ self._cache[conversation_id] = result
|
|
|
+
|
|
|
def get_cached_result(self, conversation_id: str) -> List[dict]:
|
|
|
"""
|
|
|
根据conversation_id获取缓存结果
|
|
|
:param conversation_id: 会话ID
|
|
|
:return: 结果列表
|
|
|
"""
|
|
|
- if not conversation_id:
|
|
|
- return []
|
|
|
- from cache import get_cache, set_cache
|
|
|
- cached_result = get_cache(conversation_id)
|
|
|
- if cached_result:
|
|
|
- return cached_result
|
|
|
- return []
|
|
|
+ return self.get_cache(conversation_id)
|
|
|
|
|
|
|
|
|
|