fix: dont double cache documents
This commit is contained in:
12
lib/cache.ts
12
lib/cache.ts
@@ -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),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user