MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readFileCached

Method readFileCached

src/resolution/index.ts:939–958  ·  view source on GitHub ↗

`readFile` through the LRU content cache (null = read failed, also cached).

(filePath: string)

Source from the content-addressed store, hash-verified

937
938 /** `readFile` through the LRU content cache (null = read failed, also cached). */
939 private readFileCached(filePath: string): string | null {
940 if (this.fileCache.has(filePath)) {
941 return this.fileCache.get(filePath)!;
942 }
943 const fullPath = path.join(this.projectRoot, filePath);
944 try {
945 // Import resolvers may follow package metadata to an archive (`file:*.har`,
946 // for example). Reject anything extraction would not accept before UTF-8
947 // decoding can multiply a large binary blob into gigabytes of V8 heap.
948 // Read for names, never for a megabyte of hex (see withoutLongRuns).
949 const source = readSourceText(fullPath);
950 const content = source === null ? null : withoutLongRuns(source);
951 this.fileCache.set(filePath, content);
952 return content;
953 } catch (error) {
954 logDebug('Failed to read file for resolution', { filePath, error: String(error) });
955 this.fileCache.set(filePath, null);
956 return null;
957 }
958 }
959
960 /**
961 * `readFileCached(filePath)?.includes(needle)` for an ASCII needle, searched

Callers 1

createContextMethod · 0.95

Calls 7

readSourceTextFunction · 0.90
withoutLongRunsFunction · 0.90
logDebugFunction · 0.90
hasMethod · 0.80
getMethod · 0.65
joinMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected