Return cached extraction for this file if hash matches, else None. Cache key: SHA256 of file contents. Cache value: stored as graphify-out/cache/{hash}.json Returns None if no cache entry or file has changed.
(path: Path, root: Path = Path("."))
| 19 | |
| 20 | |
| 21 | def load_cached(path: Path, root: Path = Path(".")) -> dict | None: |
| 22 | """Return cached extraction for this file if hash matches, else None. |
| 23 | |
| 24 | Cache key: SHA256 of file contents. |
| 25 | Cache value: stored as graphify-out/cache/{hash}.json |
| 26 | Returns None if no cache entry or file has changed. |
| 27 | """ |
| 28 | try: |
| 29 | h = file_hash(path) |
| 30 | except OSError: |
| 31 | return None |
| 32 | entry = cache_dir(root) / f"{h}.json" |
| 33 | if not entry.exists(): |
| 34 | return None |
| 35 | try: |
| 36 | return json.loads(entry.read_text()) |
| 37 | except (json.JSONDecodeError, OSError): |
| 38 | return None |
| 39 | |
| 40 | |
| 41 | def save_cached(path: Path, result: dict, root: Path = Path(".")) -> None: |