← Public packages
@kody/kody-factory
Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.
Files
/**
* Module-scoped in-memory cache with TTLs. No storage writes.
* Entries are keyed by string; each has a TTL after which it is stale.
*/
const store = new Map<string, { data: unknown; at: number }>()
export function memGet<T>(key: string, ttlMs: number): T | undefined {
const hit = store.get(key)
if (!hit || Date.now() - hit.at > ttlMs) return undefined
return hit.data as T
}
export function memSet<T>(key: string, data: T): void {
store.set(key, { data, at: Date.now() })
}
export async function memCached<T>(key: string, ttlMs: number, fn: () => Promise<T>): Promise<T> {
const hit = memGet<T>(key, ttlMs)
if (hit !== undefined) return hit
const data = await fn()
memSet(key, data)
return data
}