- go-client → kenaito-conf-go-client - python-client → kenaito-conf-python-client - python-client-demo → kenaito-conf-python-client-demo - nodejs-client → kenaito-conf-nodejs-client - nodejs-client-demo → kenaito-conf-nodejs-client-demo - 更新所有 README 和 package.json 中的路径引用
26 lines
553 B
JavaScript
26 lines
553 B
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const CACHE_FILE = 'config-cache.json';
|
|
|
|
export class Cache {
|
|
constructor(cacheDir = '.') {
|
|
this.cacheDir = cacheDir;
|
|
}
|
|
|
|
write(data) {
|
|
const filePath = path.join(this.cacheDir, CACHE_FILE);
|
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');
|
|
}
|
|
|
|
read() {
|
|
const filePath = path.join(this.cacheDir, CACHE_FILE);
|
|
try {
|
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
return JSON.parse(content);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
}
|