function ttlCache
ttlCache<
K,
V,
>
(
ttlMs: number,
now?: () => number,
maxEntries?: number,
): TtlCache<K, V>

Create a TTL (Time-To-Live) cache. Entries expire after ttlMs milliseconds. Accepts an optional clock function for testing. Give maxEntries a value to bound the cache: storing a new key at the cap drops the oldest-stored entry first. Bound any cache whose keys can be chosen from outside (e.g. unknown session cookies), so a flood of unique keys cannot grow it without limit. Leave it unset for caches whose keyspace our own data already bounds — the keyed entity caches rely on holding every row of their table.

Type Parameters

Parameters

ttlMs: number
optional
now: () => number = [Date.now]
optional
maxEntries: number

Return Type

Usage

import { ttlCache } from "doc.ts";