from __future__ import annotations from time import time from typing import Any _CACHE: dict[str, tuple[float, Any]] = {} def get_cache(key: str): item = _CACHE.get(key) if not item: return None expires_at, value = item if time() >= expires_at: _CACHE.pop(key, None) return None return value def set_cache(key: str, value: Any, ttl_seconds: int): _CACHE[key] = (time() + ttl_seconds, value) def cache_stats() -> dict[str, int]: return {"entries": len(_CACHE)}