ForcePilot/backend/package/yuxi/channels/adapters/twitch/outbound_cache.py
Kris 1f78c44b03 refactor: 整理并清理项目中的冗余代码与格式问题
这是一个批量整理提交,包含以下主要改动:
1.  删除多处冗余的空行和未使用的导入
2.  修复文件末尾缺少换行符的问题
3.  调整部分模块的导入顺序与代码排版
4.  修复部分配置默认值与策略逻辑
5.  新增多个功能模块与辅助工具
6.  完善异常处理与日志记录
7.  修复速率限制、消息缓存、权限校验等逻辑bug
8.  废弃部分旧有API与配置项并添加警告提示
2026-05-12 14:51:53 +08:00

26 lines
746 B
Python

from __future__ import annotations
import time
from collections import OrderedDict
from typing import Any
class OutboundCacheManager:
def __init__(self, max_size: int = 500):
self._cache: OrderedDict[str, dict[str, Any]] = OrderedDict()
self._max_size = max_size
def record(self, target: str, content: str) -> None:
entry = {
"channel": target,
"content": content,
"timestamp": time.time(),
}
cache_key = f"{target}:{len(self._cache)}"
self._cache[cache_key] = entry
while len(self._cache) > self._max_size:
self._cache.popitem(last=False)
def get_all(self) -> list[dict[str, Any]]:
return list(self._cache.values())