import { Document } from "@lib/documents.ts"; import * as cache from "@lib/cache/cache.ts"; const CACHE_INTERVAL = 20; // 5 seconds; const CACHE_KEY = "documents"; export async function getDocuments() { const res = await cache.get(CACHE_KEY); if (res) return JSON.parse(res); return; } export function setDocuments(documents: Document[]) { return cache.set( CACHE_KEY, JSON.stringify(documents), { expires: CACHE_INTERVAL }, ); } export function getDocument(id: string) { return cache.get(CACHE_KEY + "/" + id); } export async function setDocument(id: string, content: string) { await cache.set( CACHE_KEY + "/" + id, content, { expires: CACHE_INTERVAL }, ); }