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

Method readFileCached

src/resolution/index.ts:925–942  ·  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

923
924 /** `readFile` through the LRU content cache (null = read failed, also cached). */
925 private readFileCached(filePath: string): string | null {
926 if (this.fileCache.has(filePath)) {
927 return this.fileCache.get(filePath)!;
928 }
929 const fullPath = path.join(this.projectRoot, filePath);
930 try {
931 // Import resolvers may follow package metadata to an archive (`file:*.har`,
932 // for example). Reject anything extraction would not accept before UTF-8
933 // decoding can multiply a large binary blob into gigabytes of V8 heap.
934 const content = readSourceText(fullPath);
935 this.fileCache.set(filePath, content);
936 return content;
937 } catch (error) {
938 logDebug('Failed to read file for resolution', { filePath, error: String(error) });
939 this.fileCache.set(filePath, null);
940 return null;
941 }
942 }
943
944 /**
945 * `readFileCached(filePath)?.includes(needle)` for an ASCII needle, searched

Callers 1

createContextMethod · 0.95

Calls 6

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

Tested by

no test coverage detected