chore: initialize project repository

This commit is contained in:
Codex
2026-09-09 21:55:37 +08:00
commit b1497fd2c6
167 changed files with 17690 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
from typing import Any, Protocol
class CacheClient(Protocol):
async def get(self, key: str) -> Any: ...
async def set(self, key: str, value: str, ex: int | None = None) -> Any: ...
class CacheReadResult:
def __init__(self, value: Any, degraded: bool = False) -> None:
self.value = value
self.degraded = degraded
class MemoryCacheAdapter:
"""Cache is an optimization; failures must not block MySQL recall."""
def __init__(self, client: CacheClient) -> None:
self.client = client
async def get(self, key: str) -> CacheReadResult:
try:
return CacheReadResult(await self.client.get(key))
except Exception:
return CacheReadResult(None, degraded=True)
async def set(self, key: str, value: str, ttl_seconds: int = 300) -> bool:
try:
await self.client.set(key, value, ex=ttl_seconds)
return True
except Exception:
return False