function cachedTable
cachedTable<
Row,
Input,
Cached = Row,
>
(config: { fetchAll: () => Promise<Cached[]>; name: string; table: Table<Row, Input>; dependsOn?: readonly DependsOnEntry[]; }): { getAll: () => Promise<Cached[]>; invalidate: () => void; table: Table<Row, Input>; }

Bundle a request-scoped cache around a table.

Wires together the pieces every cached table used to repeat by hand:

  • a requestCache over fetchAll (the decrypted/mapped rows),
  • registration with the cache-stats registry under name, and
  • registration with the table→cache invalidation registry, so any write to the table (or to a dependsOn table whose triggers feed it) clears the cache automatically at the db-client layer — no per-write-path call.

fetchAll may resolve a richer row type than the table's own Row (e.g. listings cached with attendee counts), captured by Cached.

Type Parameters

Row
Input
Cached = Row

Parameters

config: { fetchAll: () => Promise<Cached[]>; name: string; table: Table<Row, Input>; dependsOn?: readonly DependsOnEntry[]; }

Return Type

{ getAll: () => Promise<Cached[]>; invalidate: () => void; table: Table<Row, Input>; }

Usage

import { cachedTable } from "docs/database.ts";