MCPcopy Create free account
hub / github.com/FastLED/FastLED / load_cache

Function load_cache

ci/meson/src_metadata_cache.py:76–114  ·  view source on GitHub ↗

Load cached source metadata from build directory. Args: build_dir: Meson build directory (e.g., .build/meson-quick/) Returns: Cache entry with version, hash, timestamp, and metadata None if cache doesn't exist or is invalid

(build_dir: Path)

Source from the content-addressed store, hash-verified

74
75
76def load_cache(build_dir: Path) -> CacheEntry | None:
77 """
78 Load cached source metadata from build directory.
79
80 Args:
81 build_dir: Meson build directory (e.g., .build/meson-quick/)
82
83 Returns:
84 Cache entry with version, hash, timestamp, and metadata
85 None if cache doesn't exist or is invalid
86 """
87 cache_file = build_dir / CACHE_FILENAME
88 if not cache_file.exists():
89 return None
90
91 try:
92 with open(cache_file, "r", encoding="utf-8") as f:
93 cache = json.load(f)
94
95 # Validate cache structure
96 required_keys = ["version", "hash", "timestamp", "metadata"]
97 if not all(key in cache for key in required_keys):
98 return None
99 if cache["version"] != CACHE_VERSION:
100 return None
101
102 return CacheEntry(
103 version=int(cache["version"]),
104 hash=str(cache["hash"]),
105 timestamp=float(cache["timestamp"]),
106 metadata=str(cache["metadata"]),
107 )
108 except KeyboardInterrupt as ki:
109 import _thread
110
111 _thread.interrupt_main()
112 raise ki
113 except (json.JSONDecodeError, OSError):
114 return None
115
116
117def save_cache(build_dir: Path, src_hash: str, metadata: str) -> None:

Callers 1

mainFunction · 0.70

Calls 3

allFunction · 0.85
CacheEntryClass · 0.70
loadMethod · 0.45

Tested by

no test coverage detected