Project Files
src / cache / pageCache.ts
import { CrawlSession } from "../types/CrawlSession";
import { MAX_CACHE_SIZE } from "../utils/constants";
export const cache = new Map<
string,
CrawlSession
>();
export function cleanupCache(): void {
if (cache.size <= MAX_CACHE_SIZE) {
return;
}
const oldest = [...cache.entries()]
.sort(
(a, b) =>
a[1].createdAt -
b[1].createdAt
)
.slice(
0,
cache.size - MAX_CACHE_SIZE
);
for (const [key] of oldest) {
cache.delete(key);
}
}