// In-memory per-game cache. A game the player has opened once is kept here so a // later re-entry renders instantly from the cache while a fresh fetch updates it in // the background — removing the blank "loading" flash and the full redraw on every // lobby <-> game navigation. It is intentionally process-memory only (no persistence): // stale entries are corrected by the background refresh, and the cache is cleared on // logout. import type { MoveRecord, StateView } from './model'; export interface CachedGame { view: StateView; moves: MoveRecord[]; } const cache = new Map(); /** getCachedGame returns the last-seen state+history for a game, or undefined. */ export function getCachedGame(id: string): CachedGame | undefined { return cache.get(id); } /** setCachedGame stores the latest state+history for a game. */ export function setCachedGame(id: string, view: StateView, moves: MoveRecord[]): void { cache.set(id, { view, moves }); } /** clearGameCache drops every cached game (called on logout). */ export function clearGameCache(): void { cache.clear(); }