refactor(backend): split log files into separate file
This commit is contained in:
13
lib/cache.ts
13
lib/cache.ts
@@ -6,12 +6,18 @@ interface SetCacheOptions {
|
||||
expires?: number; // Override expiration for individual cache entries
|
||||
}
|
||||
|
||||
export const caches = new Map<
|
||||
string,
|
||||
{ info: () => { count: number; sizeInKB: number } }
|
||||
>();
|
||||
|
||||
export function createCache<T>(
|
||||
cacheName: string,
|
||||
createOpts: CreateCacheOptions = {},
|
||||
) {
|
||||
const cache = new Map<string, { value: T; expiresAt?: number }>();
|
||||
|
||||
return {
|
||||
const api = {
|
||||
get(key: string): T | undefined {
|
||||
const entry = cache.get(key);
|
||||
if (!entry) return undefined;
|
||||
@@ -86,4 +92,9 @@ export function createCache<T>(
|
||||
return cache.size;
|
||||
},
|
||||
};
|
||||
|
||||
caches.set(cacheName, {
|
||||
info: api.info.bind(api),
|
||||
});
|
||||
return api;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user