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

Method readFileCached

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

825
826 /** `readFile` through the LRU content cache (null = read failed, also cached). */
827 private readFileCached(filePath: string): string | null {
828 if (this.fileCache.has(filePath)) {
829 return this.fileCache.get(filePath)!;
830 }
831 const fullPath = path.join(this.projectRoot, filePath);
832 try {
833 // Import resolvers may follow package metadata to an archive (`file:*.har`,
834 // for example). Reject anything extraction would not accept before UTF-8
835 // decoding can multiply a large binary blob into gigabytes of V8 heap.
836 const content = readSourceText(fullPath);
837 this.fileCache.set(filePath, content);
838 return content;
839 } catch (error) {
840 logDebug('Failed to read file for resolution', { filePath, error: String(error) });
841 this.fileCache.set(filePath, null);
842 return null;
843 }
844 }
845
846 /**
847 * `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