MCPcopy Create free account
hub / github.com/DSGWJQ/Feagent / get

Method get

src/infrastructure/memory/in_memory_cache.py:82–123  ·  view source on GitHub ↗

获取缓存的消息列表 执行逻辑: 1. 检查缓存是否存在 2. 检查 TTL 是否过期 3. 检查有效性标记 4. 更新访问时间 + LRU 排序 5. 返回消息副本 Args: workflow_id: 工作流 ID Returns: - list[ChatMessage]: 缓存命中 - None: 缓存未命中/过期/失效

(self, workflow_id: str)

Source from the content-addressed store, hash-verified

80 self._misses = 0
81
82 def get(self, workflow_id: str) -> list[ChatMessage] | None:
83 """
84 获取缓存的消息列表
85
86 执行逻辑:
87 1. 检查缓存是否存在
88 2. 检查 TTL 是否过期
89 3. 检查有效性标记
90 4. 更新访问时间 + LRU 排序
91 5. 返回消息副本
92
93 Args:
94 workflow_id: 工作流 ID
95
96 Returns:
97 - list[ChatMessage]: 缓存命中
98 - None: 缓存未命中/过期/失效
99 """
100 if workflow_id not in self._cache:
101 self._misses += 1
102 return None
103
104 entry = self._cache[workflow_id]
105
106 # 检查 TTL
107 if datetime.utcnow() - entry.last_access > self._ttl:
108 self._misses += 1
109 del self._cache[workflow_id]
110 return None
111
112 # 检查有效性标记
113 if not entry.is_valid:
114 self._misses += 1
115 return None
116
117 # 命中:更新访问时间 + LRU 移动到末尾
118 entry.last_access = datetime.utcnow()
119 self._cache.move_to_end(workflow_id)
120 self._hits += 1
121
122 # 返回副本(避免外部修改)
123 return entry.messages.copy()
124
125 def put(self, workflow_id: str, messages: list[ChatMessage]) -> None:
126 """

Callers 15

_load_required_keysMethod · 0.45
execute_asyncMethod · 0.45
executeMethod · 0.45
executeMethod · 0.45
executeMethod · 0.45
executeMethod · 0.45
executeMethod · 0.45
_for_each_loopMethod · 0.45
_range_loopMethod · 0.45
_while_loopMethod · 0.45
_get_nested_valueMethod · 0.45
executeMethod · 0.45

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected