Spaces:
Sleeping
Sleeping
Update app/core/cache.py
Browse files1234567891011121314151617import time_CACHE = {"df": None, "ts": 0.0}def get_cache(ttl: float):now = time.time()if _CACHE["df"] is not None and (now - _CACHE["ts"]) < ttl:return _CACHE["df"]return Nonedef set_cache(df):_CACHE["df"] = df_CACHE["ts"] = time.time()def last_update_iso():from datetime import datetime, timezonereturn datetime.fromtimestamp(_CACHE["ts"], tz=timezone.utc).isoformat()12345678910111213141516171819202122232425262728293031323334353637"""Cache Management for Pegos Data API-----------------------------------Dataset son indirilme zamanı ve DataFrame cache yapısı."""import timefrom datetime import datetime, timezoneimport pandas as pdfrom huggingface_hub import hf_hub_download_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)if ts <= 0:return 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()if _CACHE["df"] is not None and (now - _CACHE["ts"] < _CACHE_TTL):return _CACHE["df"]local_path = hf_hub_download(repo_id=repo_id,filename=filename,repo_type="dataset",token=token,force_download=True,)df = pd.read_csv(local_path)_CACHE["df"], _CACHE["ts"] = df, now # ✅ zaman damgası burada güncelleniyorreturn df
app/core/cache.py+30-10