/** * Shared state for tile cache invalidation after admin "Rebuild zooms". * Admin sets the timestamp on success; MapView on mount clears tile caches * when a rebuild was done recently, so the map shows fresh tiles even if * SSE was missed (e.g. admin in another tab). */ const REBUILD_DONE_TTL_MS = 5 * 60 * 1000 // 5 minutes export function useRebuildZoomsInvalidation() { const rebuildZoomsDoneAt = useState('rebuildZoomsDoneAt', () => 0) function markRebuildDone() { rebuildZoomsDoneAt.value = Date.now() } function shouldInvalidateTileCache(): boolean { if (rebuildZoomsDoneAt.value <= 0) return false return Date.now() - rebuildZoomsDoneAt.value < REBUILD_DONE_TTL_MS } function clearRebuildDoneFlag() { rebuildZoomsDoneAt.value = 0 } return { markRebuildDone, shouldInvalidateTileCache, clearRebuildDoneFlag, } }