接口添加缓存策略

This commit is contained in:
2026-08-16 21:41:46 +08:00
parent f192a08384
commit 436a126e3b
3 changed files with 11 additions and 4 deletions

View File

@@ -65,7 +65,8 @@ async def cache_set(key: str, value: Any, ttl: int) -> None:
if c is None:
return
try:
await c.set(key, json.dumps(value, ensure_ascii=False), ex=max(1, ttl))
# default=strvalue 里混入 datetime/date 也不炸(炸了会触发 _bail 毒死整个缓存层)
await c.set(key, json.dumps(value, ensure_ascii=False, default=str), ex=max(1, ttl))
except Exception: # noqa: BLE001
_bail()