fix: dont double cache documents

This commit is contained in:
2025-01-25 18:51:10 +01:00
parent 0f146ea699
commit 23f33b7472
6 changed files with 40 additions and 18 deletions

View File

@@ -6,9 +6,12 @@ interface SetCacheOptions {
expires?: number; // Override expiration for individual cache entries
}
const caches = new Map<
export const caches = new Map<
string,
{ info: () => { name: string; count: number; sizeInKB: number } }
{
info: () => { name: string; count: number; sizeInKB: number };
clear: () => void;
}
>();
export function createCache<T>(
@@ -31,6 +34,10 @@ export function createCache<T>(
return entry.value; // Return value if not expired
},
clear() {
cache.clear();
},
set(key: string, value: T | unknown, opts: SetCacheOptions = {}) {
const now = Date.now();
const expiresIn = opts.expires ?? createOpts.expires;
@@ -94,6 +101,7 @@ export function createCache<T>(
};
caches.set(cacheName, {
clear: api.clear.bind(api),
info: api.info.bind(api),
});