Project Files
src / cache / cache.ts
interface CacheEntry<T> {
data: T;
expiresAt: number;
}
const cache = new Map<string, CacheEntry<unknown>>();
export function getCache<T>(
key: string
): T | null {
const entry = cache.get(key);
if (!entry) {
return null;
}
if (entry.expiresAt < Date.now()) {
cache.delete(key);
return null;
}
return entry.data as T;
}
export function setCache<T>(
key: string,
value: T,
ttl: number
): void {
cache.set(key, {
data: value,
expiresAt: Date.now() + ttl
});
}