Interface: TscacheClient
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
features | readonly | ReadonlySet<WorkerFeature> | The optional features this client's worker offers (N79): empty for a worker script from before them (a stale cached script during a deploy). Without 'cacheChanged', its listeners are never called; without 'calendar-grid', cache() rejects a calendar interval. |
mode | readonly | HostingMode | Which hosting won the fallback chain. |
superseded | readonly | | { lib: string; } | undefined | Set once a worker of a newer generation of this application (another tscache version, fetcher module or worker build) is running in the origin (N132): lib is that worker's tscache version. This tab's worker no longer persists; the tab keeps working from memory and its fetcher, and a reload joins the newer worker. Undefined until then. When the superseded event reached this tab before createClient resolved, this is set from the start and the event follows on the next macrotask or with the worker's next message, whichever comes first, so a listener attached in the same turn as await createClient() hears it. An event still on its way then (the worker was superseded, but its message had not reached this tab) arrives live and sets this when it does. Read this in code that may run after the event. Only a worker that lists the feature can report it: where client.features.has('superseded') is false (a dedicated worker, the in-process hosting, an older worker script), this stays undefined for good and means "not known", not "current". |
Methods
cache()
cache(config): Promise<CacheHandle>;Get-or-create (N4). Rejects with ConfigError, before anything is sent, for a calendar interval when the worker does not list 'calendar-grid' in features (N119).
Parameters
| Parameter | Type |
|---|---|
config | CacheConfig |
Returns
Promise<CacheHandle>
clearAll()
clearAll(): Promise<void>;Empties every cache; in SharedWorker mode this affects ALL tabs. Where the browser has IndexedDB it also empties the persisted records, from any hosting (N54, N66), and resolves once the disk is empty or the clear gave up at its deadline; it never rejects for a disk failure. So it does in a tab whose worker is superseded. It also reaches the other SharedWorkers of the origin of 0.3.0 or later (N135), which clear their caches and the disk too; a 0.1.0 or 0.2.0 worker is not reached, and the promise does not wait for them. Their tabs hear cacheCleared, possibly more than once. Afterwards every SharedWorker that ran the clear, the caller's and each one the relay reached, loads no stored records for the rest of its life, so a persisted cache it first opens afterwards starts empty. The logout's limits are in the persistence guide, "Sensitive data and logout" (site/guides/persistence.md).
Returns
Promise<void>
dispose()
dispose(): Promise<void>;Releases the port and anything this client owns. Idempotent.
Returns
Promise<void>
memoryStats()
memoryStats(): Promise<MemoryStats>;What the worker's caches hold now (§2.9): the budget in force, the bytes the cached points hold, the pinned part, the pages evicted so far and one entry per cache. In a SharedWorker it covers the caches of every tab of that worker, never another deploy's worker. Rejects with TscacheError against a worker that does not offer memory budgets (client.features.has('memoryBudget') is false).
Returns
Promise<MemoryStats>
off()
off<E>(event, fn): void;Type Parameters
| Type Parameter |
|---|
E extends keyof ClientEvents |
Parameters
| Parameter | Type |
|---|---|
event | E |
fn | (payload) => void |
Returns
void
on()
on<E>(event, fn): () => void;Events, including workerLost (N32): the worker behind this client is gone, every pending and later call rejects, and a new client is needed. A cacheChanged listener here hears every cache's changes; the first one subscribes this client to them and the last one's removal ends it.
Type Parameters
| Type Parameter |
|---|
E extends keyof ClientEvents |
Parameters
| Parameter | Type |
|---|---|
event | E |
fn | (payload) => void |
Returns
() => void
updateAuth()
updateAuth(context): Promise<void>;Delivers new auth material to the fetcher (step ⑪).
Parameters
| Parameter | Type |
|---|---|
context | unknown |
Returns
Promise<void>