Skip to content

Coverage and gaps ​

A cache keeps two things apart:

  • Data: the points that exist, each with a value for every field.
  • Coverage: the time ranges the cache knows about, because the backend answered for them.

A slot inside coverage without a point is a confirmed gap: a weekend, a night between trading sessions, an hour a sensor was offline. It is never fetched again. A slot outside coverage is simply not known yet, whether or not a point happens to be there.

What a read returns ​

get(range) resolves with a GetResult:

FieldHolds
timestampsthe timestamps of every present point in the range, ascending (Float64Array)
fieldsone typed array per field, of the field's dtype, as long as timestamps
coveragethe authoritative sub-ranges of the request, ascending
missesthe rest of the request, each { range, reason, error? }; always present, possibly empty
snapshotonly when asked for with { snapshot: true } (Snapshots)

coverage and misses tile the request exactly: every slot is in one of them. The arrays hold present points only: no holes, no mask, the same shape whatever the cache's internal layout.

A read returns every present point in the range, covered or not. The live tail, which is never covered (see Versions and watermarks), still shows its newest bar, and a range you invalidated stays on screen until its refetch replaces it. coverage says which parts are authoritative.

The arrays are copies, never views into the cache's memory; they are moved to the page without a second copy, and you own them.

Miss reasons ​

ReasonMeansWhat to do
'uncached'not known: no fetcher is configured, you read with cacheOnly, the cache was cleared while the read waited and again while it asked once more (versions), or it is the provisional tail, which is never covered and so stays a miss even right after its fetch returned its pointsfetch and put it yourself, or read without cacheOnly; for the tail, nothing: its points are in the result
'fetch-failed'the fetch threw, or its response failed validation; error has its name and messageread again later; nothing about the failure is cached
'auth-pending'credentials are invalid, so the fetch was not made, or it was refusedrefresh, call updateAuth, read again (Credentials)

get never rejects because data is unavailable. It rejects only for programmer errors: an invalid range, an unknown cache, a disposed client (Errors).

How a read fetches ​

With a fetcher configured, and without cacheOnly, a read:

  1. computes the uncovered parts of the request;
  2. subtracts the fetches already in flight for the same cache, from any tab, and awaits them for the overlap instead of fetching it again (dedup);
  3. coalesces the rest: adjacent misses merge, and a miss that abuts existing coverage is extended by one interval into it, so the response overlaps what is known by one point and the ranges join. A miss that abuts a fetch in flight is not extended into it;
  4. issues one fetch per coalesced range;
  5. writes each response as authoritative for its whole range, below the response's own watermark;
  6. reads once, after every fetch it awaited, and resolves.

Two reads of the same range share one fetch, and a read that overlaps a fetch in flight asks only for what lies outside it, so a chart that scrolls faster than the backend answers asks for each bar once. A fetch that never settles holds every read that needs one of its slots, so a fetcher bounds its requests (Writing a fetcher).

Claiming a range yourself ​

put writes points without a fetcher. What it claims:

  • Without options.range, the batch's own span, from its first to its last timestamp. It adds or overwrites the points it carries and removes nothing. This is safe for streaming appends.
  • With options.range, that whole range, which must contain every timestamp of the batch. Slots in it without a point become confirmed gaps, and points already inside it that the batch does not carry are removed: afterwards the range holds exactly the batch's points. A range that is not on the grid covers only the grid points inside it.
ts
const t0 = Date.UTC(2026, 9, 30, 9, 0);
// Without a range: adds or overwrites these points, claims their own span.
await cache.put({
  timestamps: [t0, t0 + MINUTE, t0 + 2 * MINUTE],
  fields: { temperature: [21.5, 21.7, Number.NaN], errors: [0, 0, 1] },
});
// With a range: the answer for 09:00–09:59, so the slots without a point
// become confirmed gaps, and points the batch omits are removed.
const { warnings } = await cache.put(
  {
    timestamps: new Float64Array([t0, t0 + MINUTE]),
    fields: {
      temperature: new Float32Array([21.5, 21.8]),
      errors: new Uint16Array([0, 0]),
    },
  },
  { range: { start: t0, end: t0 + 59 * MINUTE } },
);
console.log(warnings); // non-empty only with warnOnOverlapDiff
// The typed arrays above were transferred to the worker: they are now
// detached. Pass copies if you still need them.

A wrong claim is undone only by invalidate. Every orchestrated fetch is a claim of the second kind, for the range it asked for, which is why a fetcher must return the whole range (Writing a fetcher).

Why a separate index ​

Coverage is a sorted array of disjoint ranges per cache, searched by bisection. Ranges merge whenever they touch, and a confirmed gap does not split coverage, so the array stays at tens of entries; the architecture document records why an interval tree or a skip list was not worth it (§6.1 of architecture.md).