({ cacheDir, key, value })
| 43 | * Write JSON cache entry atomically. |
| 44 | */ |
| 45 | export function writeJsonCache({ cacheDir, key, value }) { |
| 46 | ensureDir(cacheDir); |
| 47 | const filePath = cachePath(cacheDir, key); |
| 48 | const tmpPath = `${filePath}.tmp.${process.pid}`; |
| 49 | fs.writeFileSync(tmpPath, `${JSON.stringify(value, null, 2)}\n`, 'utf-8'); |
| 50 | fs.renameSync(tmpPath, filePath); |
| 51 | } |
| 52 |
no test coverage detected