12345678910111213141516171819202122 |
- import time
- from pqai_agent.toolkit.hot_topic_toolkit import HotTopicToolkit
- class HotTopicClient:
- def __init__(self):
- self._cache = None
- self._cache_time = 0
- self._cache_ttl = 300 # 5分钟
- self._toolkit = HotTopicToolkit()
- def get_hot_topics(self):
- now = time.time()
- if self._cache and (now - self._cache_time) < self._cache_ttl:
- return self._cache
- topics = self._toolkit.get_hot_topics()
- self._cache = topics
- self._cache_time = now
- return topics
- # 全局可用实例
- hot_topic_client = HotTopicClient()
|