Collection: refresh() method
Available since
@irtio/room 0.1Hosted roomsirt dev@irtio/testingSelf-hosted room hostThe refresh() method of the Collection interface drops what the room’s cache holds of the collection’s entries, so the next get() of each reads it from the data service.
Syntax
refresh()
Parameters
None.
Return value
None (undefined).
Description
Without refresh(), a write made outside the room shows in the room’s get() within 5 seconds. list() is never cached, so it needs no refresh.
Examples
Rereading a level its author just edited
// reload.ts
import { defineRoom } from "@irtio/room";
export default defineRoom({
async onMessage(room, connection, message) {
const m = message as { type?: string; level?: string };
if (m.type !== "reload" || typeof m.level !== "string") return;
const levels = room.collection("levels");
levels.refresh();
const level = await levels.get(m.level);
room.send(connection, { type: "level", level: level?.value ?? null });
},
});
See also
Runtime availability
| Hosted rooms | irt dev | @irtio/testing | Self-hosted room host | |
|---|---|---|---|---|
refresh() | 0.1 | 0.1 | 0.1 | 0.1 |