import fs from 'fs/promises'; import path from 'path'; const TOKEN_CACHE_DIR = path.join(process.cwd(), 'token_cache'); export async function loadCache(userId: string): Promise { try { const filePath = path.join(TOKEN_CACHE_DIR, `${userId}.json`); return await fs.readFile(filePath, 'utf-8'); } catch { return null; } } export async function saveCache(userId: string, data: string) { await fs.mkdir(TOKEN_CACHE_DIR, { recursive: true }); const filePath = path.join(TOKEN_CACHE_DIR, `${userId}.json`); await fs.writeFile(filePath, data); } export async function clearCache(userId: string) { try { const filePath = path.join(TOKEN_CACHE_DIR, `${userId}.json`); await fs.unlink(filePath); } catch {} }