pre-tiptap

This commit is contained in:
Michael Freno
2025-12-19 12:04:18 -05:00
parent 324141441b
commit 3d55dab7b5
13 changed files with 555 additions and 409 deletions

54
src/server/cache.ts Normal file
View File

@@ -0,0 +1,54 @@
interface CacheEntry<T> {
data: T;
timestamp: number;
}
class SimpleCache {
private cache: Map<string, CacheEntry<any>> = new Map();
get<T>(key: string, ttlMs: number): T | null {
const entry = this.cache.get(key);
if (!entry) return null;
const now = Date.now();
if (now - entry.timestamp > ttlMs) {
this.cache.delete(key);
return null;
}
return entry.data as T;
}
set<T>(key: string, data: T): void {
this.cache.set(key, {
data,
timestamp: Date.now()
});
}
clear(): void {
this.cache.clear();
}
delete(key: string): void {
this.cache.delete(key);
}
}
export const cache = new SimpleCache();
// Helper function to wrap async operations with caching
export async function withCache<T>(
key: string,
ttlMs: number,
fn: () => Promise<T>
): Promise<T> {
const cached = cache.get<T>(key, ttlMs);
if (cached !== null) {
return cached;
}
const result = await fn();
cache.set(key, result);
return result;
}