Files
kenaito-conf/nodejs-client/lib/cache.js
T
odboy 98c5b62d0d feat(client): 添加 Node.js 客户端及示例应用
- 新增 nodejs-client 模块,提供 ConfigClient 配置拉取、定时同步、变更监听
- 使用 Node.js 内置 crypto 模块实现 AES 解密,零外部依赖
- 新增 nodejs-client-demo Express 示例应用,端口 8083
- 更新 README.md,补充 Python 和 Node.js 客户端使用说明
- 修复 fetchAllConfigs API 响应格式判断逻辑
2026-02-08 21:02:57 +08:00

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;
}
}
}