from typing import Generic, NamedTuple from gallery.sketch.source import ApiSource from gallery.util import TimeUnit from .api import API, Api class CachePreset(NamedTuple): ttl: int = TimeUnit.HOUR alias: str = "redis" DEFAULT_CACHE_PRESET = CachePreset() class CachedApi(Api, Generic[API]): CACHE_KEY: str def __init__(self, api: API): self._api = api def _build_source(self) -> ApiSource: raise RuntimeError("Source not used in CachedApi") @property def provider(self) -> str: return self._api.provider