Spaces:
Sleeping
Sleeping
Update app/core/cache.py
Browse files12345674 unmodified lines1213141516171 unmodified line1920212223248 unmodified lines3334353637"""Cache Management for Pegos Data API-----------------------------------Dataset son indirilme zamanı ve DataFrame cache yapısı."""import time4 unmodified lines_CACHE = {"df": None, "ts": 0.0}_CACHE_TTL = 180.0 # 3 dakika cachedef last_update_iso() -> str:"""Cache zamanını ISO formatında döndürür."""ts = _CACHE.get("ts", 0.0)1 unmodified linereturn datetime(1970, 1, 1, tzinfo=timezone.utc).isoformat()return datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()def load_dataset(repo_id: str, filename: str, token: str) -> pd.DataFrame:"""Dataset'i Hugging Face'ten indirir veya cache'ten döndürür."""now = time.time()8 unmodified linesforce_download=True,)df = pd.read_csv(local_path)_CACHE["df"], _CACHE["ts"] = df, now # ✅ zaman damgası burada güncelleniyorreturn df12345674 unmodified lines121314151617181 unmodified line202122232425268 unmodified lines353637383940"""Cache Management for Pegos Data API-----------------------------------Dataset cache ve zaman yönetimi."""import time4 unmodified lines_CACHE = {"df": None, "ts": 0.0}_CACHE_TTL = 180.0 # 3 dakika cachedef last_update_iso() -> str:"""Cache zamanını ISO formatında döndürür."""ts = _CACHE.get("ts", 0.0)1 unmodified linereturn datetime(1970, 1, 1, tzinfo=timezone.utc).isoformat()return datetime.fromtimestamp(ts, tz=timezone.utc).isoformat()def load_dataset(repo_id: str, filename: str, token: str) -> pd.DataFrame:"""Dataset'i Hugging Face'ten indirir veya cache'ten döndürür."""now = time.time()8 unmodified linesforce_download=True,)df = pd.read_csv(local_path)_CACHE["df"], _CACHE["ts"] = df, nowprint(f"[INFO] Dataset sync ✅ {len(df)} rows @ {last_update_iso()}")return df
app/core/cache.py+5-2