function collectionCache
collectionCache<T>(
fetchAll: () => Promise<T[]>,
ttlMs: number,
now?: () => number,
): CollectionCache<T>

Create an in-memory collection cache with TTL. Loads all items via fetchAll on first access or after invalidation/expiry, then serves from memory until the TTL expires or invalidate() is called. Accepts an optional clock function for testing.

Type Parameters

Parameters

fetchAll: () => Promise<T[]>
ttlMs: number
optional
now: () => number = [Date.now]

Return Type

Usage

import { collectionCache } from "doc.ts";