from datetime import datetime, timedelta from typing import Dict, List, Optional, Tuple from pynyaata.cache import CACHE_TIMEOUT from pynyaata.types import Cache, RemoteFile CACHE_DATA: Dict[str, Tuple[List[RemoteFile], datetime]] = {} class SimpleCache(Cache): def get(self, key: str) -> Optional[List[RemoteFile]]: if key in CACHE_DATA: data, timeout = CACHE_DATA[key] if datetime.now() > timeout + timedelta(seconds=CACHE_TIMEOUT): return data else: CACHE_DATA.pop(key) return None def set(self, key: str, data: List[RemoteFile]): CACHE_DATA[key] = (data, datetime.now())