API Reference

invalidate()

Removes a single channel's cached entry from IndexedDB. The narrowest tool in the engine — one targeted key removal, nothing else — for the cases where you know exactly one store's disk cache is wrong and want it gone before the next read.

Prerequisites
  • flux created via createFlux() — see api/create-flux
  • A store already registered under the channel you're invalidating — see api/register
1

Basic usage

Call flux.invalidate(channel) with the channel name you registered the store under. It returns a promise that resolves once the IDB entry is gone.
typescript
1// Removes this channel's cached entry from IndexedDB
2await flux.invalidate('pricing')
3
4// The in-memory store is untouched — this only clears what's on disk.
5// The next hydrate() or bootstrap() call for this channel now sees a
6// cold cache instead of the entry you just removed.
2

What it does under the hood

Internally this is a thin wrapper over idbDelete — the same primitive flux.destroy() and the multi-tenant sweep routines use elsewhere, called here for exactly one key rather than a prefix-matched batch.
typescript
1// invalidate(channel) resolves the matching registration, then calls
2// idbDelete with that store's own resolved key — a single targeted
3// removal, not a partition-wide sweep.
4
5function invalidate(channel: string) {
6 const reg = registry.get(channel)
7 if (!reg) return
8
9 const scope = reg.scope ?? 'global'
10 return idbDelete(reg.idbKey, storagePrefix, scope, scope === 'user' ? currentUserId : undefined)
11}
3

Scope-aware resolution

Because it resolves the key the same way every other IDB call in Flux does, invalidating a 'user'-scoped channel only ever touches the currently active user's namespaced entry — never another tenant's copy of the same channel name.
typescript
1// Scope resolution mirrors every other IDB call in Flux — idbGet,
2// idbSet, and idbDelete all take the same (key, storagePrefix, scope, userId)
3// shape, so invalidate() never needs a separate userId argument from you.
4
5flux.register({
6 channel: 'dashboard',
7 idbKey: 'dashboard:summary',
8 scope: 'user',
9 /* ... */
10})
11
12// Clears only the currently active user's cached copy —
13// resolved internally from the engine's own currentUserId
14await flux.invalidate('dashboard')
4

This is not a refetch

invalidate() only deletes what's cached — it never fires a network request on its own. Pair it explicitly with a bootstrap() call if you want fresh data immediately, or leave the channel cold and let it repopulate the next time bootstrap runs.
typescript
1// invalidate() only clears the cache entry — it does not fetch
2// fresh data on its own. Pair it with whatever refetch mechanism
3// fits the situation: a manual bootstrap() call, or simply letting
4// the channel sit cold until the next natural bootstrap/revalidation.
5
6await flux.invalidate('pricing')
7await flux.bootstrap({ endpoint: '/api/bootstrap', map: { pricing: 'pricing' } })
5

FluxErrorBoundary — the built-in consumer

The most common caller of invalidate() isn't application code at all — it's FluxErrorBoundary in flux-react, which catches a data-shape crash from a malformed cached payload and clears it automatically.
typescript
1// flux-react's FluxErrorBoundary is the main built-in consumer of
2// invalidate() — it wraps a component, catches a data-shape crash,
3// invalidates the channel, and re-fetches rather than leaving the
4// component permanently broken on a malformed cached payload.
5
6import { FluxErrorBoundary } from '@tsworldtech/flux-react'
7
8<FluxErrorBoundary channel="pricing">
9 <PricingTable />
10</FluxErrorBoundary>
Reach for this before a manual IDB clear

If you're debugging a store stuck on stale or malformed cached data, invalidate(channel) is the targeted equivalent of clearing that one IDB entry by hand in devtools — without needing to know the resolved key shape yourself.

For clearing every channel belonging to a logged-out user at once, see api/clear-user-session. For repopulating a channel after invalidating it, see api/bootstrap.