(workspace: WorkspaceStructure)
| 23 | * Returns empty cache if file doesn't exist or on error |
| 24 | */ |
| 25 | export 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 |
no test coverage detected