@ifc-lite/cache 3.8.0 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -10
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @ifc-lite/cache
|
|
2
2
|
|
|
3
|
-
Binary cache format for IFClite. Caches the parsed data store and geometry in a compact binary format so a previously-loaded IFC reopens
|
|
3
|
+
Binary cache format for IFClite. Caches the parsed data store and geometry in a compact binary format so a previously-loaded IFC reopens without re-running the full parse + tessellation pipeline (see [Performance](https://ifclite.dev/docs/guide/performance/)). Content-addressable (xxHash64 of the source IFC), so cache invalidation is automatic.
|
|
4
4
|
|
|
5
5
|
**Properties and quantities are not part of that speedup.** `BinaryCacheWriter.write` serializes whatever the data store's property/quantity tables already hold. A STEP-parsed store resolves properties lazily on demand and never populates those tables, so a cache written straight from a STEP parse round-trips with EMPTY property/quantity tables — a cache-restored model queries properties exactly as slow as a fresh parse (see `docs/guide/querying.md`). If your application needs fast repeat property queries too, retain the source buffer alongside the cache entry and re-attach on-demand extraction on read, the way the viewer's cache hook does.
|
|
6
6
|
|
|
@@ -15,6 +15,12 @@ Format v25 keeps each mesh's optional `shadingColor`, pre-placement
|
|
|
15
15
|
fields stay absent; a pre-v25 entry reads them as unknown and is rebuilt once
|
|
16
16
|
through the versioned cache key.
|
|
17
17
|
|
|
18
|
+
Format v26 and v28 invalidate older relationship graphs through the versioned
|
|
19
|
+
cache key (v26 changes no bytes; v28 adds the parser relationship-coverage
|
|
20
|
+
trailer to the entity-index section). Format v27 adds the optional IfcSite
|
|
21
|
+
world origin (`CoordinateInfo.siteOrigin`). The current version is the exported
|
|
22
|
+
`FORMAT_VERSION`; [`SPEC.md`](./SPEC.md) lists every version.
|
|
23
|
+
|
|
18
24
|
## Installation
|
|
19
25
|
|
|
20
26
|
```bash
|
|
@@ -25,6 +31,7 @@ npm install @ifc-lite/cache
|
|
|
25
31
|
|
|
26
32
|
```typescript
|
|
27
33
|
import {
|
|
34
|
+
FORMAT_VERSION,
|
|
28
35
|
xxhash64Hex,
|
|
29
36
|
BinaryCacheReader,
|
|
30
37
|
BinaryCacheWriter,
|
|
@@ -41,15 +48,20 @@ declare const myStorage: {
|
|
|
41
48
|
|
|
42
49
|
async function loadWithCache(file: File) {
|
|
43
50
|
const ifcBuffer = await file.arrayBuffer();
|
|
44
|
-
|
|
51
|
+
// Put FORMAT_VERSION in the key so a format bump misses old entries.
|
|
52
|
+
const cacheKey = `${xxhash64Hex(ifcBuffer)}-v${FORMAT_VERSION}`;
|
|
45
53
|
|
|
46
54
|
// Try cache first
|
|
47
55
|
const cached = await myStorage.get(cacheKey);
|
|
48
56
|
if (cached) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
const hit = await new BinaryCacheReader().read(cached).catch(error => {
|
|
58
|
+
console.warn('Could not read the IFC cache; rebuilding it.', error);
|
|
59
|
+
return null;
|
|
60
|
+
});
|
|
61
|
+
if (hit) {
|
|
62
|
+
renderer.loadGeometry(hit.geometry?.meshes ?? []);
|
|
63
|
+
return; // no parse, no tessellation
|
|
64
|
+
}
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
// Cold path — full parse + tessellation, then write the cache.
|
|
@@ -90,27 +102,47 @@ Two hash functions are exposed for cache key generation:
|
|
|
90
102
|
```typescript
|
|
91
103
|
import { xxhash64, xxhash64Hex } from '@ifc-lite/cache';
|
|
92
104
|
|
|
93
|
-
const hexKey = xxhash64Hex(buffer); //
|
|
105
|
+
const hexKey = xxhash64Hex(buffer); // 16-char hex string
|
|
94
106
|
const rawKey = xxhash64(buffer); // same hash as a bigint
|
|
95
107
|
```
|
|
96
108
|
|
|
97
109
|
The cache keys models by the xxHash64 of the source IFC, and `reader.validate(cacheBuffer, sourceBuffer)` uses the same hash to detect when the source has changed.
|
|
98
110
|
|
|
111
|
+
## Source fingerprints
|
|
112
|
+
|
|
113
|
+
`computeSourceFingerprint(bytes)` returns a `SourceFingerprint` (`{ hex, hash }`) using the byte length, a head window, a tail window when the file extends beyond the head, and eight interior windows. The amount read is bounded, so it is a cheap lookup key, not a content check: an edit that keeps the length and falls between the sampled windows gives the same fingerprint. `computeSourceFingerprintFromBlob(file)` gives the same result from a `Blob`/`File` through bounded slice reads. `sourceModelIdentity(name, bytes)` returns `` `${name}:${hex}` ``, the model identity the viewer, the CLI and the MCP server match rule-set `targets.modelFingerprints` against.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { computeSourceFingerprint, computeSourceFingerprintFromBlob, sourceModelIdentity } from '@ifc-lite/cache';
|
|
117
|
+
|
|
118
|
+
const { hex } = computeSourceFingerprint(buffer);
|
|
119
|
+
const same = await computeSourceFingerprintFromBlob(file); // same value for the same bytes
|
|
120
|
+
const identity = sourceModelIdentity('office.ifc', buffer);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Building a cache outside the browser
|
|
124
|
+
|
|
125
|
+
`ifc-build-cache` is a native CLI that writes this format from an IFC file without a browser or the WASM heap, so a server, a build step or a function can prepare the cache that `BinaryCacheReader` then reads. It installs through cargo from the repository. See the [Native Cache Builder guide](https://ifclite.dev/docs/guide/native-cache/) for installation, which format version a build writes, and what a native cache leaves out.
|
|
126
|
+
|
|
99
127
|
## Format versioning
|
|
100
128
|
|
|
101
129
|
The byte-level layout, the reader's compatibility rules and the conformance criterion for another writer are specified in [`SPEC.md`](./SPEC.md).
|
|
102
130
|
|
|
103
|
-
The binary layout is versioned via the exported `FORMAT_VERSION` constant. Readers accept entries written by the current or an older format version (with backward-compatible decoding, e.g. the per-mesh
|
|
131
|
+
The binary layout is versioned via the exported `FORMAT_VERSION` constant. Readers accept entries written by the current or an older format version (with backward-compatible decoding, e.g. the per-mesh source ids added in v14) and reject entries written by a newer one, so mixed-version deployments fail safely toward a cold parse. One exception: `read()` throws on geometry written before v13 (`skipGeometry: true` still reads the rest), so discard such an entry and rebuild it. Nonempty quantity tables written through v16, and nonempty property tables written before the `psetGlobalId` column was added during v16, are decoded with the current layout and can be misread; rebuild such entries. `skipGeometry: true` bypasses only the geometry check. `SPEC.md` §11 lists every version gate.
|
|
104
132
|
|
|
105
133
|
Version 19 preserves explicitly supplied canonical `MeshData.appearanceSource` provenance. Fresh canonical meshes store an identity marker; fragmented or expanded meshes reference a geometry-header source-index pool, shared across spatial chunks, plus their corner mapping. Restored metadata points to the restored mesh indices, preserving the topology identity fence required by appearance preview. Invalid identities, source lengths, pool references and corner ranges fail cache reading/writing instead of enabling an unsafe preview. Unmarked meshes remain unmarked; old records never acquire inferred canonical identity.
|
|
106
134
|
|
|
107
135
|
Version 20 appends the optional exact WASM RTC producer frame to `CoordinateInfo`, including an authoritative `needsShift: false` and a meaningful `true` frame at the zero origin. Direct reads of v13–v19 geometry remain supported with this provenance absent; it is never inferred from the older applied-only `wasmRtcOffset` field. Frame-present records strictly validate finite coordinates, the boolean decision, and offset consistency. Frame-absent records preserve legacy numeric offset values (including old non-finite values) for compatibility, without treating them as exact provenance.
|
|
108
136
|
|
|
109
|
-
The viewer includes `FORMAT_VERSION` in its cache key, so older entries reparse once and receive real provenance from the canonical geometry pipeline. Direct readers can still decode v13–v19 records for viewing, with metadata introduced by newer versions absent. When reading an older geometry header directly, pass its version as the second argument to `readGeometryHeadV13(reader, version)`; it defaults to the current format. Keep the returned chunk metadata when calling `decodeGeometryChunk`, since it carries the shared source-index pool. This does not add UV/image caching: texture-carrying viewer models retain their existing cache bypass.
|
|
137
|
+
The viewer includes `FORMAT_VERSION` in its cache key, so older entries reparse once and receive real provenance from the canonical geometry pipeline. Direct readers can still decode v13–v19 records for viewing, with metadata introduced by newer versions absent. When reading an older geometry header directly, pass its version as the second argument to `readGeometryHeadV13(reader, version)`; it defaults to the current format. Keep the returned chunk metadata when calling `decodeGeometryChunk`, since it carries the shared source-index pool. `read()`, `openGeometryChunksV13` and `decodeGeometryChunk` also accept `sharedArena: true`, which copies a chunk's mesh arrays into shared blocks instead of one buffer per array; such an array is a view into a shared block, so copy it (`array.slice()`) before transferring it. This does not add UV/image caching: texture-carrying viewer models retain their existing cache bypass.
|
|
138
|
+
|
|
139
|
+
## Inflating chunks off the main thread
|
|
140
|
+
|
|
141
|
+
`@ifc-lite/cache/chunk-inflate-pool` is a separate entry, so a browser host can load it lazily. `ChunkInflatePool` inflates a cache hit's compressed geometry chunks on a few workers; pass it in the options argument: `openGeometryChunksV13(buffer, sectionOffset, version, { inflate: pool.inflate })`. Output is byte-identical to `inflateRaw`. A worker failure falls back to inflating on the calling thread; a chunk that does not inflate there either rejects with `CorruptChunkError`, so the caller can delete the entry and parse fresh.
|
|
110
142
|
|
|
111
143
|
## Source-hash contract (and `omitSourceHash`)
|
|
112
144
|
|
|
113
|
-
By default the header stores the full-file `xxhash64` of the source in `sourceHash`, and `reader.validate()` / `read({ sourceBuffer })` compare against it. Hashing a large source
|
|
145
|
+
By default the header stores the full-file `xxhash64` of the source in `sourceHash`, and `reader.validate()` / `read({ sourceBuffer })` compare against it. Hashing a large source is a full-file pass on the main thread (see [Performance](https://ifclite.dev/docs/guide/performance/)), so a caller that validates the source **another way** (e.g. an application-layer content hash plus a file modified-time guard, as the viewer's source-decoupled cache tier does) can pass `omitSourceHash: true`:
|
|
114
146
|
|
|
115
147
|
```typescript
|
|
116
148
|
import { BinaryCacheWriter, type CacheDataStore } from '@ifc-lite/cache';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ifc-lite/cache",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.2",
|
|
4
4
|
"description": "Binary cache format for IFC-Lite - fast model loading",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@ifc-lite/data": "^7.
|
|
22
|
-
"@ifc-lite/geometry": "^
|
|
21
|
+
"@ifc-lite/data": "^7.1.0",
|
|
22
|
+
"@ifc-lite/geometry": "^9.0.0",
|
|
23
23
|
"@ifc-lite/load-trace": "^0.4.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@mergifyio/vitest": "^2026.
|
|
26
|
+
"@mergifyio/vitest": "^2026.11.8",
|
|
27
27
|
"typescript": "^6.0.3",
|
|
28
|
-
"vitest": "^5.0
|
|
29
|
-
"@ifc-lite/parser": "^
|
|
28
|
+
"vitest": "^5.1.0",
|
|
29
|
+
"@ifc-lite/parser": "^11.1.0"
|
|
30
30
|
},
|
|
31
31
|
"license": "MPL-2.0",
|
|
32
32
|
"author": "Louis True",
|