MCPcopy Create free account
hub / github.com/MigoXLab/coderio / loadCodeCache

Function loadCodeCache

src/utils/code-cache.ts:25–50  ·  view source on GitHub ↗
(workspace: WorkspaceStructure)

Source from the content-addressed store, hash-verified

23 * Returns empty cache if file doesn't exist or on error
24 */
25export function loadCodeCache(workspace: WorkspaceStructure): CodeCache {
26 const cachePath = getCachePath(workspace);
27
28 try {
29 if (!fs.existsSync(cachePath)) {
30 logger.printInfoLog('No code cache found, starting fresh');
31 return createEmptyCache();
32 }
33
34 const content = fs.readFileSync(cachePath, 'utf-8');
35 const cache = JSON.parse(content) as CodeCache;
36
37 // Validate cache structure
38 if (!Array.isArray(cache.generatedComponents) || typeof cache.appInjected !== 'boolean') {
39 logger.printWarnLog('Invalid cache format, starting fresh');
40 return createEmptyCache();
41 }
42
43 logger.printInfoLog(`Loaded code cache: ${cache.generatedComponents.length} components cached`);
44 return cache;
45 } catch (error) {
46 const errorMessage = error instanceof Error ? error.message : String(error);
47 logger.printWarnLog(`Failed to load code cache: ${errorMessage}. Starting fresh.`);
48 return createEmptyCache();
49 }
50}
51
52/**
53 * Save code generation cache to file

Callers 2

generateCodeFunction · 0.90
code-cache.test.tsFile · 0.90

Calls 2

getCachePathFunction · 0.85
createEmptyCacheFunction · 0.85

Tested by

no test coverage detected