Spaces:
Sleeping
Sleeping
Download src/services/cache_service.py from faseehsandhu/Digitalytics: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/spaces/faseehsandhu/Digitalytics/resolve/main/src/services/cache_service.py
- Command line
-
hf download hf://spaces/faseehsandhu/Digitalytics/src/services/cache_service.py
-
curl -L -o cache_service.py https://huggingface.co/spaces/faseehsandhu/Digitalytics/resolve/main/src/services/cache_service.py
861 Bytes
| """cache_service.py | |
| Simple JSON-based cache utilities for retrieval index and embeddings. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| from typing import Any, Optional | |
| DEFAULT_CACHE_DIR = ".cache" | |
| def ensure_cache_dir(cache_dir: str = DEFAULT_CACHE_DIR) -> Path: | |
| p = Path(cache_dir) | |
| p.mkdir(parents=True, exist_ok=True) | |
| return p | |
| def load_json(path: Path) -> Optional[Any]: | |
| try: | |
| if path.exists(): | |
| with path.open("r", encoding="utf-8") as f: | |
| return json.load(f) | |
| except Exception: | |
| return None | |
| return None | |
| def save_json(path: Path, data: Any) -> bool: | |
| try: | |
| path.parent.mkdir(parents=True, exist_ok=True) | |
| with path.open("w", encoding="utf-8") as f: | |
| json.dump(data, f) | |
| return True | |
| except Exception: | |
| return False | |