export type CacheKey = string export interface CacheEntry { data: Data now: Date // should be equal to `project.now` (not equal to datetime of cache entry creation) } export async function getData($cache: { [key: string]: CacheEntry }, key: string, getter: () => Promise, now: Date) { const result = $cache[key] if (result && result.now === now) { return result.data } else { const data = await getter() $cache[key] = { data, now } return data } }