MCPcopy
hub / github.com/safishamsi/graphify / load_cached

Function load_cached

graphify/cache.py:21–38  ·  view source on GitHub ↗

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("."))

Source from the content-addressed store, hash-verified

19
20
21def 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
41def save_cached(path: Path, result: dict, root: Path = Path(".")) -> None:

Callers 4

test_cache_roundtripFunction · 0.90
check_semantic_cacheFunction · 0.85
extractFunction · 0.85

Calls 2

file_hashFunction · 0.85
cache_dirFunction · 0.85

Tested by 2

test_cache_roundtripFunction · 0.72