Cache channels

A cache channel keeps its last event for 30 minutes, and a new subscriber receives it straight away. Late joiners see the current state without asking your backend: a score, a room's topic, a price.

Names

PrefixWorks like
cache-A public channel
private-cache-A private channel
presence-cache-A presence channel

Use them

client.ts
const score = thunderclap.subscribe("cache-match-7");

score.bind("score", (data) => render(data)); // also called with the cached event
score.on("cache_miss", () => requestFreshScore()); // nothing cached yet

The cached event arrives just before subscribed. When nothing is cached, the channel emits cache_miss instead, and your server can publish a fresh value.

Only events published by your server are cached, never client events.

To be told on your server when a subscriber finds a cache channel empty, use the cache_miss webhook.