Skip to content

Data model ​

One cache is one CacheState inside the engine. It holds four things: the points, stored in dense segments on the cache's grid; the coverage index, which records which slots are known; the dataset version; and the finalized watermark. The diagram shows one small cache; the explanations below follow it from top to bottom.

tscache data modelA row of 24 grid slots with points; the dense segments that hold them, split by a gap longer than gapSplitK and by a page edge; the coverage ranges kept apart from the points; the misses a read reports; and the finalized watermark at slot 20, after which points are provisional and never covered.Gridt = alignmentOffset + slot × intervalSlotsgrid points0246810121416182022SegmentsDenseSegment runssegment ABsegment C1 empty slot: same segment6 empty slots > gapSplitK (4): splitpage edge (segmentSlotCap = 16)inside segment Apresence mask, one bit per slot:1 1 1 1 0 1 1 1one typed array per field, of its dtypeno timestamps: a slot's position gives its tdataset version (optional)set by config.version or the firstmeta.version; a put or response withanother one clears points and coverage,then is applied (cacheCleared)CoverageCoverageIndexcovered 0–11covered 14–19crosses the page edge and segments B, Cget(0…23)a cache-only readmissmissreturns every present point, coverage 0–11 and 14–19, and 'uncached' missesfinalized watermark (finalizedUntil) at slot 20provisionalSlot statescovered, pointreturned; fetched again only at a miss's edgecovered, no pointa confirmed real gapnot covered, no pointa miss: a fetching get asks for itnot covered, pointreturned and asked for againprovisional point: at or after the watermark; stored and returned, its slot never covered

The example uses gapSplitK 4 and, so that a page edge fits in the picture, a segmentSlotCap of 16 (the default is 32 768). Its watermark puts the first provisional slot at 20.

Grid and slots ​

A cache's interval and alignmentOffset define its grid: the timestamps t = alignmentOffset + slot × interval for integer slots. Every point a cache stores lies on a grid point, and a cache stores at most one point per slot. All range arithmetic runs on slot indices; one module, grid.ts, converts between milliseconds and slots.

  • A read or an invalidation snaps its range outward: the start down to the slot at or before it, the end up to the slot at or after it.
  • A put's authority range snaps inward, to the grid points inside it, so a put never claims a slot its caller did not name.
  • A put's timestamps must lie on the grid exactly.

Drawn from:

Segments ​

The points live in DenseSegments. A segment covers a run of consecutive slots with one typed array per field, of the field's dtype, and a presence mask of one bit per slot. A slot's timestamp is not stored: it follows from the slot's position.

The cache's SegmentStore decides where one segment ends and the next begins. Two present points with no present point between them share a segment exactly when

  • at most gapSplitK slots between them hold no point (default 4), and
  • they lie on the same page: pages are segmentSlotCap slots long and start at multiples of it (default 32 768).

In the diagram, segment A keeps the one empty slot 4; the six empty slots 8 to 13 split A from B; the page edge at slot 16 splits B from C, although slots 15 and 16 both hold points. The layout therefore depends only on which points are present, never on the order in which they arrived.

Drawn from:

Coverage ​

Coverage is kept apart from the points. The CoverageIndex is a sorted list of disjoint, non-adjacent slot ranges, each meaning "the backend was asked about these slots, and the answer is final". A put records the slots it is authoritative for (its range, or without one the span of its points), minus the provisional slots; overlapping and adjacent ranges merge, and an invalidation subtracts a range, which may split one in two. Coverage ignores segments and pages: in the diagram, the range 14 to 19 runs across the page edge and across both segment B and segment C.

Together, coverage and points give each slot one of four states:

Slot stateWhat a read doesIn the diagram
covered, with a pointreturns the point; fetched again only at a miss's edge0–3, 5–7, 14–17, 19
covered, no pointreturns nothing: a confirmed real gap4, 8–11, 18
not covered, no pointreports it in a miss; a fetching read asks for it12–13, 22–23
not covered, a pointreturns the point, and a fetching read asks again20–21

A read returns every present point in its range, covered or not, with the covered sub-ranges and the uncovered ones as misses of reason 'uncached'; the two tile the range exactly. When the orchestrator served the read, it relabels the part of a miss left by a failed fetch, or by auth going invalid, as 'fetch-failed' or 'auth-pending': a range it did not fetch because auth was invalid, and a fetch still running when auth went invalid, both come back 'auth-pending'.

A covered slot never causes a fetch by itself, but it can be fetched again as part of a miss's fetch: the orchestrator extends each miss by one slot into the coverage next to it, so with slot 0 covered and slot 1 missing it asks for slots 0 to 1.

The last state arises in two ways: an invalidation forgets coverage but keeps the points, and points at or after the watermark are never covered.

Drawn from:

The watermark ​

finalizedUntil is the cache's finalized watermark, in milliseconds. Its slot is the first grid point at or after it; from that slot on, points are provisional. They are stored and returned, but their slots are never recorded as coverage, so every fetching read that includes them asks the backend again, and the answer's values overwrite them.

  • It starts at CacheConfig.finalizedUntil, when the config sets one.
  • A put's or a response's meta.finalizedUntil only moves it forwards. Such a put is also authoritative only below its own watermark: past it, its points are merged but replace nothing and record no coverage.
  • setFinalizedUntil(t) sets it exactly. Moving it back withdraws coverage from its new slot on.

Drawn from:

The dataset version ​

A cache can carry a dataset version, a non-empty string. It comes from CacheConfig.version, or else from the first meta.version a put or a response reports. A put or a response with a different version clears the cache's points and coverage, adopts the new version and is then applied; the engine reports the clear as cacheCleared with reason 'version-mismatch'. A put without meta.version leaves the version as it is.

Drawn from:

The same data, outside the engine ​

A segment leaves the engine as a DenseSegmentPayload: its first timestamp, its slot count, the grid, the mask and one little-endian buffer per field. A Snapshot wraps the payloads of a range with that range's coverage, version and watermark. The same snapshot is what get(range, { snapshot: true }) returns for server rendering and what the persister stores, one per page, in IndexedDB.

Drawn from: