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

Method readFileCached

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

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