import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs"; import { join } from "path"; interface Cache { access_token?: string; } class CacheManager { cache: Cache = {}; TEMP_DIR = join(process.cwd(), ".temp"); TEMP_FILE = join(this.TEMP_DIR, "server_cache"); constructor() { this.init(); } init() { if (!existsSync(this.TEMP_DIR)) { mkdirSync(this.TEMP_DIR); } if (!existsSync(this.TEMP_FILE)) { writeFileSync(this.TEMP_FILE, "{}", { flag: "w", }); } } load() { this.cache = JSON.parse(readFileSync(this.TEMP_FILE).toString()); } save() { writeFileSync(this.TEMP_FILE, JSON.stringify(this.cache), { flag: "w", }); } } export const cacheManager = new CacheManager();