loadCacheFromDisk() — mcp Function Reference
Architecture documentation for the loadCacheFromDisk() function in graph-cache.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD f528cae6_71d3_4b84_026d_d4778648e9c8["loadCacheFromDisk()"] 08ca54b2_22bc_134f_e028_7c18da8dca8a["start()"] 08ca54b2_22bc_134f_e028_7c18da8dca8a -->|calls| f528cae6_71d3_4b84_026d_d4778648e9c8 b8971bfc_ba3c_23a9_1f17_5d613ac67105["debug()"] f528cae6_71d3_4b84_026d_d4778648e9c8 -->|calls| b8971bfc_ba3c_23a9_1f17_5d613ac67105 dfe11f52_4dd3_db89_9717_941d05bae091["warn()"] f528cae6_71d3_4b84_026d_d4778648e9c8 -->|calls| dfe11f52_4dd3_db89_9717_941d05bae091 2f679171_fd3f_3cd5_48b2_587cc9ec01fd["buildIndexes()"] f528cae6_71d3_4b84_026d_d4778648e9c8 -->|calls| 2f679171_fd3f_3cd5_48b2_587cc9ec01fd b965d3cf_dacd_81fc_77e7_dbe9bdef8bbc["set()"] f528cae6_71d3_4b84_026d_d4778648e9c8 -->|calls| b965d3cf_dacd_81fc_77e7_dbe9bdef8bbc c652ed9f_2901_0635_2a5b_fc305e9cd6c1["has()"] f528cae6_71d3_4b84_026d_d4778648e9c8 -->|calls| c652ed9f_2901_0635_2a5b_fc305e9cd6c1 style f528cae6_71d3_4b84_026d_d4778648e9c8 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/cache/graph-cache.ts lines 398–458
export async function loadCacheFromDisk(
cacheDir: string,
cache: GraphCache
): Promise<Map<string, IndexedGraph>> {
const repoMap = new Map<string, IndexedGraph>();
let entries: string[];
try {
entries = await fs.readdir(cacheDir);
} catch (error: any) {
if (error.code === 'ENOENT') {
logger.debug('Cache directory does not exist:', cacheDir);
return repoMap;
}
throw error;
}
const jsonFiles = entries.filter(e => e.endsWith('.json'));
logger.debug(`Found ${jsonFiles.length} cache files in ${cacheDir}`);
for (const file of jsonFiles) {
try {
const filePath = join(cacheDir, file);
const content = await fs.readFile(filePath, 'utf-8');
const payload = JSON.parse(content);
if (!payload.raw || !payload.repoName) {
logger.warn(`Skipping invalid cache file: ${file}`);
continue;
}
const repoName = payload.repoName as string;
const cacheKey = `precache:${repoName}`;
const graph = buildIndexes(payload.raw, cacheKey);
cache.set(cacheKey, graph);
repoMap.set(repoName.toLowerCase(), graph);
// Index by commit hash for exact matching (e.g. "commit:abc1234")
const commitHash = payload.commitHash as string | null;
if (commitHash) {
repoMap.set(`commit:${commitHash}`, graph);
}
// Also store common variants of the repo name for matching
// e.g. "django" for "django__django", "astropy" for "astropy__astropy"
const parts = repoName.toLowerCase().split(/[_\-\/]/);
for (const part of parts) {
if (part && part.length > 2 && !repoMap.has(part)) {
repoMap.set(part, graph);
}
}
logger.debug(`Loaded pre-computed graph for ${repoName} (commit: ${commitHash || 'unknown'}): ${graph.summary.nodeCount} nodes`);
} catch (error: any) {
logger.warn(`Failed to load cache file ${file}: ${error.message}`);
}
}
return repoMap;
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does loadCacheFromDisk() do?
loadCacheFromDisk() is a function in the mcp codebase.
What does loadCacheFromDisk() call?
loadCacheFromDisk() calls 5 function(s): buildIndexes, debug, has, set, warn.
What calls loadCacheFromDisk()?
loadCacheFromDisk() is called by 1 function(s): start.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free