Keeps what the server fetched from another site for a while, by key, so a page or a feed asking again doesn't refetch it: Bandcamp tracklists, YouTube playlists, and link previews. Each holder sets how long an entry lives and how many are kept; past that count, the oldest written goes first.
c
TtlCache<V>()
ttlMs: number,
maxEntries: number
A map whose entries expire ttlMs after they are written, holding
maxEntries at most.
-
clear(): void
Empties the cache, for the tests' reset between cases.
-
delete(): voidkey: string,value?: V
Removes
key, or only whenvalueis still what it holds, so a late failure can't remove the entry that replaced its own. -
get(key: string): V | undefined
Returns the value under
keyunless it is missing or expired. -
set(): Vkey: string,value: V
Stores
valueunderkeyfrom now on, and returns it.
Usage
import * as mod from "api/lib/ttl-cache.ts";