Skip to main content

Module cache

Module cache 

Source
Expand description

Per-account RAM cache for Community sync state.

Consolidates what were three scattered LazyLock statics (oldest-page cursor, history-start floors, in-flight page de-dup) into ONE structure under ONE invalidation key: the session generation. Any access after an account swap — which bumps current_session_generation() — transparently resets the cache, so stale per-channel state can never bleed into the next account. Holds the page cursors (oldest back-paging floor + newest since floor), history-start flags, and in-flight page de-dup; future RAM-cache work (e.g. invite preload) layers onto the same structure + invalidation discipline.

Functions§

abort_preload
The warm-up fetch failed/was cancelled — drop the entry so an adopter falls back immediately.
advance_newest_cursor
Advance the latest-page since floor to the newest wire time this page returned (monotonic — only ever steps forward). Call ONLY for latest-page fetches.
advance_oldest_cursor
Advance the back-paging cursor to the oldest wire time this page returned (monotonic — only ever steps further back).
begin_preload
Mark a community’s warm-up as in-flight (so a racing Join adopts it rather than double-fetching). Evicts stale/cross-generation entries and, if over the cap, the oldest.
clear
Drop all cached state (account swap / reset). Access-time generation checks self-reset too, so this is an explicit belt-and-suspenders teardown.
clear_channel_floors
Clear a channel’s back-paging floors (history-start + oldest cursor) — e.g. after a multi-epoch backfill makes older history reachable again.
clear_channel_sync_state
Drop ALL of a channel’s sync state (floors + the latest-page since cursor) — community teardown. A surviving since cursor makes a same-session REJOIN sync “since I left” instead of cold, so the rejoined chat opens empty despite plenty of history.
end_page_fetch
Release an in-flight page-fetch claim (success or error).
finish_preload
The warm-up fetch landed — make its page available to promote/adopt.
is_at_history_start
Has the channel’s network history-start been reached? Older pages then stay DB-only.
mark_history_start
Mark the channel as having reached its network history-start.
newest_cursor
Newest OUTER created_at (seconds) seen on a latest page for the channel — the since floor for the next latest fetch. None before the first latest fetch this session (→ full newest page).
oldest_cursor
Oldest OUTER created_at (seconds) fetched for the channel — the back-paging cursor.
take_or_await_preload
Adopt a community’s warm-up as this sync’s page: Ready → take it; Pending → await it (the in-flight fetch IS the page, so this waits only the request’s remaining time, never firing a second); absent/stale/failed → None so the caller fetches normally. Polls at coarse granularity (imperceptible vs. a fresh round-trip) to stay free of notification races.
take_ready_preload
Non-blocking take for promotion at Accept: returns the page ONLY if already Ready, leaving a still-Pending warm-up in place for the sync to adopt. None if absent / Pending / stale.
try_begin_page_fetch
Claim an in-flight page fetch (key "{channel_id}:{older|latest}"). Returns false if one is already running — the caller should no-op. Pair with end_page_fetch.