@blaze-cache/core 0.4.0-beta.2 → 0.5.0-beta.1
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 +131 -44
- package/dist/cache.d.ts +67 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +608 -28
- package/dist/cache.js.map +1 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/multitab.d.ts +140 -0
- package/dist/multitab.d.ts.map +1 -0
- package/dist/multitab.js +306 -0
- package/dist/multitab.js.map +1 -0
- package/dist/persistence/indexeddb.d.ts.map +1 -1
- package/dist/persistence/indexeddb.js +8 -2
- package/dist/persistence/indexeddb.js.map +1 -1
- package/dist/query.d.ts +102 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +116 -0
- package/dist/query.js.map +1 -0
- package/dist/reactivity.d.ts.map +1 -1
- package/dist/shared.d.ts +52 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +100 -0
- package/dist/shared.js.map +1 -0
- package/dist/types.d.ts +48 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +16 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -0
- package/dist/utils.js.map +1 -1
- package/dist/wasm.d.ts +38 -0
- package/dist/wasm.d.ts.map +1 -1
- package/dist/wasm.js +189 -5
- package/dist/wasm.js.map +1 -1
- package/package.json +6 -2
- package/pkg/blaze_cache_wasm.d.ts +157 -0
- package/pkg/blaze_cache_wasm.js +460 -0
- package/pkg/blaze_cache_wasm_bg.wasm +0 -0
- package/pkg/blaze_cache_wasm_bg.wasm.d.ts +23 -0
- package/pkg/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/blaze-cache/blaze-cache/main/docs/blaze-cache-logo.png" alt="Blaze Cache logo" width="150">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/blaze-cache/blaze-cache/main/docs/assets/blaze-cache-logo.png" alt="Blaze Cache logo" width="150">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<h1 align="center">@blaze-cache/core</h1>
|
|
@@ -33,15 +33,15 @@ const cache = await createCache({ capacity: 1000, persistence: { namespace: 'app
|
|
|
33
33
|
|
|
34
34
|
cache.set('user:42', { name: 'Ada' }, { ttlMs: 30_000, tags: ['user:42'] });
|
|
35
35
|
|
|
36
|
-
cache.get('user:42');
|
|
37
|
-
cache.peek('user:42');
|
|
38
|
-
cache.ttl('user:42');
|
|
36
|
+
cache.get('user:42'); // { name: 'Ada' } — counted as a hit
|
|
37
|
+
cache.peek('user:42'); // the same value, with no hit recorded
|
|
38
|
+
cache.ttl('user:42'); // ~30000 — ms until it expires
|
|
39
39
|
cache.touch('user:42', { ttlMs: 60_000 }); // renew the deadline, keep the value
|
|
40
|
-
cache.invalidateTags('user:42');
|
|
41
|
-
cache.stats();
|
|
40
|
+
cache.invalidateTags('user:42'); // removes it, synchronously, and syncs IndexedDB
|
|
41
|
+
cache.stats(); // { hits, misses, evictions, expirations, … }
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
`
|
|
44
|
+
`createCache()` instantiates the wasm module once, so everything after it is **synchronous** —
|
|
45
45
|
`get`/`set` never allocate a `Promise`.
|
|
46
46
|
|
|
47
47
|
## Events
|
|
@@ -63,31 +63,31 @@ cache.on((event) => {
|
|
|
63
63
|
|
|
64
64
|
cache.once('clear', () => console.log('first clear, only once'));
|
|
65
65
|
|
|
66
|
-
cache.off('evict');
|
|
67
|
-
cache.off();
|
|
68
|
-
offEvict();
|
|
66
|
+
cache.off('evict'); // every `evict` listener
|
|
67
|
+
cache.off(); // every listener, period
|
|
68
|
+
offEvict(); // …or just this one handle (idempotent)
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
| Event
|
|
72
|
-
|
|
|
73
|
-
| `set`
|
|
74
|
-
| `delete`
|
|
75
|
-
| `clear`
|
|
76
|
-
| `invalidate` | `invalidateTags()` removed entries
|
|
77
|
-
| `prune`
|
|
78
|
-
| `touch`
|
|
79
|
-
| `evict`
|
|
80
|
-
| `expire`
|
|
81
|
-
| `hit`
|
|
82
|
-
| `miss`
|
|
71
|
+
| Event | Emitted when | Payload |
|
|
72
|
+
| ------------ | ------------------------------------------------- | -------------- |
|
|
73
|
+
| `set` | a key was stored (insert or replace) | `key` |
|
|
74
|
+
| `delete` | a key was removed and was present | `key` |
|
|
75
|
+
| `clear` | the cache was emptied | — |
|
|
76
|
+
| `invalidate` | `invalidateTags()` removed entries | `keys` |
|
|
77
|
+
| `prune` | `prune()` removed expired entries | `keys` |
|
|
78
|
+
| `touch` | `touch()` renewed a live entry's deadline | `key` |
|
|
79
|
+
| `evict` | the core dropped an entry to stay within capacity | `key`, `value` |
|
|
80
|
+
| `expire` | the core reclaimed an entry whose TTL elapsed | `key`, `value` |
|
|
81
|
+
| `hit` | `get()` / `getMany()` found a live entry | `key`, `value` |
|
|
82
|
+
| `miss` | a lookup found nothing (absent or expired) | `key` |
|
|
83
83
|
|
|
84
84
|
Eight of those are raised in TypeScript around the call you made; `evict` and `expire`
|
|
85
|
-
happen
|
|
85
|
+
happen _inside_ the Rust core and are delivered from an opt-in **drop log** — the first
|
|
86
86
|
listener interested in them switches it on through the wasm binding, and with no such
|
|
87
87
|
listener the hot path pays a single predictable branch. Listeners run synchronously in
|
|
88
88
|
registration order (typed first, wildcards last), a throwing listener is logged and
|
|
89
89
|
skipped — never able to undo a mutation — and reads that record nothing (`peek`, `has`,
|
|
90
|
-
`ttl`, `size`, `keys`, `entry`) emit nothing. A listener removed
|
|
90
|
+
`ttl`, `size`, `keys`, `entry`) emit nothing. A listener removed _during_ delivery — by
|
|
91
91
|
its own unsubscribe, by `off(type, fn)`, or wholesale by `off(type)`/`off()` — is never
|
|
92
92
|
visited for that event, and a pending `once` can be cancelled before it fires through
|
|
93
93
|
`off(type, fn)` (Node's `.listener` convention). `dispose()` clears every listener along
|
|
@@ -104,7 +104,7 @@ registered until the first one.
|
|
|
104
104
|
|
|
105
105
|
```ts
|
|
106
106
|
const stop = cache.subscribe('user:42', (user, change) => {
|
|
107
|
-
console.log(change.type, user);
|
|
107
|
+
console.log(change.type, user); // 'set' → the new value, 'delete' → undefined
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
const stopMany = cache.subscribeMany(['a', 'b'], (key, value, change) => {
|
|
@@ -115,35 +115,122 @@ const stopTag = cache.subscribeTag('user', ({ tag, keys, change }) => {
|
|
|
115
115
|
console.log(tag, keys, change.type); // 'user', ['user:42'], 'invalidate'
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
stop();
|
|
118
|
+
stop();
|
|
119
|
+
stopMany();
|
|
120
|
+
stopTag(); // idempotent — also safe from inside a listener
|
|
119
121
|
```
|
|
120
122
|
|
|
121
|
-
|
|
123
|
+
- **`value` is what the cache holds now** — the new value after `set`, the unchanged one
|
|
122
124
|
after `touch`, and `undefined` after `delete`, `evict`, `expire`, `invalidate`, `prune`
|
|
123
125
|
or `clear`. For `evict`/`expire` the dropped reference is still on `change.value`.
|
|
124
|
-
|
|
126
|
+
- **Reads never wake a subscriber** — `hit`/`miss` are not part of a subscription at all,
|
|
125
127
|
so `get`, `peek`, `has`, `ttl` … cost a subscription nothing.
|
|
126
|
-
|
|
128
|
+
- **Tag subscriptions know what the raw events cannot** — a removal carries no tags, so the
|
|
127
129
|
layer keeps a per-tag mirror of the live keys carrying it and attributes `delete`,
|
|
128
130
|
`evict`, `expire`, `invalidate`, `prune` and `clear` to the tags they actually hit.
|
|
129
|
-
|
|
131
|
+
- **Subscriptions switch on the drop log**, exactly like an `evict`/`expire` listener: the
|
|
130
132
|
Rust core only records the entries it drops by itself while somebody is waiting for them,
|
|
131
133
|
and the last stop function switches it back off.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
- **`{ once: true }`** fires a single time and unsubscribes itself.
|
|
135
|
+
- **A subscriber that throws is isolated** — logged with `console.error`, the mutation
|
|
134
136
|
stands, and the remaining subscribers still run. One that unsubscribes mid-notification
|
|
135
137
|
(through its own handle, or because a `once` sibling fired) is never visited for that
|
|
136
138
|
event.
|
|
137
|
-
|
|
139
|
+
- **All of it is opt-in** — with no subscription the layer does not exist. The first call
|
|
138
140
|
attaches eight typed listeners and snapshots the live keys; while a subscription lives, a
|
|
139
141
|
write crosses the boundary once more to re-read that key's tags (and only when a tag
|
|
140
142
|
subscription exists), and reads back a value only for keys somebody subscribed to.
|
|
141
|
-
Releasing the last subscription detaches everything again. `cache.off()` clears
|
|
143
|
+
Releasing the last subscription detaches everything again. `cache.off()` clears _event_
|
|
142
144
|
listeners only — live subscriptions re-bind their own immediately.
|
|
143
145
|
|
|
146
|
+
## Opt-in multi-tab sync
|
|
147
|
+
|
|
148
|
+
`createCache({ multiTab: { enabled: true } })` opens one `BroadcastChannel` per
|
|
149
|
+
`namespace\0generation` and propagates `set`, `delete`, `clear`, tag invalidation and rotation
|
|
150
|
+
between tabs, with a `hello`/`state` handshake on focus. Every key tracks a hybrid-logical-clock
|
|
151
|
+
version, so stale messages from a hidden tab cannot overwrite a newer value — the old
|
|
152
|
+
last-writer-wins flush bug is fixed. `strategy: 'value'` (default) structured-clones payloads
|
|
153
|
+
and falls back to a tombstone for non-cloneable values; `strategy: 'invalidate'` always sends
|
|
154
|
+
tombstones. Remote mutations emit `remote-set` / `remote-delete` / `remote-clear` /
|
|
155
|
+
`remote-invalidate` / `remote-rotate` events and are never re-broadcast. Flushes are guarded by
|
|
156
|
+
a cross-tab Web Lock where available. The option is off by default; without it no channel is
|
|
157
|
+
created and behavior is unchanged.
|
|
158
|
+
|
|
159
|
+
## Indexed queries
|
|
160
|
+
|
|
161
|
+
`keys()`/`entries()` walk every live entry. `createCache({ indexes: true })` builds opt-in
|
|
162
|
+
ordered key, expiry and tag indexes for bounded reads:
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
const cache = await createCache({ indexes: true });
|
|
166
|
+
cache.set('user:1', { name: 'Ada' }, { tags: ['user'], ttlMs: 60_000 });
|
|
167
|
+
|
|
168
|
+
const page = cache.query({ prefix: 'user:', tags: { all: ['user'] }, limit: 20 });
|
|
169
|
+
// items are metadata only: { key, ttlMs, tags }
|
|
170
|
+
const more = cache.query({ prefix: 'user:', limit: 20, cursor: page.nextCursor! });
|
|
171
|
+
cache.queryKeys({ prefix: 'user:', limit: 20 }); // keys only
|
|
172
|
+
cache.count({ prefix: 'user:' }); // number of matches
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`ttlRange: { min?, max? }` filters remaining TTL; `keys: [...]` is an allow-list; `limit` is
|
|
176
|
+
required and cursors are last-key anchors in ascending key order that survive deletion of
|
|
177
|
+
the anchor key. `query()` throws without `indexes: true` — an explicit `fullScan: true` is
|
|
178
|
+
the only O(n) path. It permits `cursor` and an optional `where` post-filter, but rejects
|
|
179
|
+
`prefix`/`tags`/`ttlRange`/`keys` (a scan would silently ignore those constraints).
|
|
180
|
+
`includeValues: true` returns live by-reference values and requires both `maxEntries` and
|
|
181
|
+
`maxValueBytes` caps. Indexes are off by default and add nothing to the hot path.
|
|
182
|
+
|
|
183
|
+
## The `@blaze-cache/core/shared` subpath
|
|
184
|
+
|
|
185
|
+
A wasm-free, server-safe subpath holding the redaction patterns (`REDACT_KEY_PATTERNS`,
|
|
186
|
+
`isRedactedKey`), the frozen duck-typed `isBlazeRecord` guard and the
|
|
187
|
+
`<binding>:<feature>` kind helpers. Snapshot bridges and framework bindings import it
|
|
188
|
+
without loading the cache runtime, wasm or IndexedDB.
|
|
189
|
+
|
|
190
|
+
## Opt-in storage modes
|
|
191
|
+
|
|
192
|
+
The default keeps values as by-reference externrefs in the Rust slab (see _Good to know_).
|
|
193
|
+
Two opt-in modes are available for workloads with different ownership needs:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { createCache } from '@blaze-cache/core';
|
|
197
|
+
|
|
198
|
+
// 1. Raw bytes live in Wasm linear memory; reads are zero-copy views.
|
|
199
|
+
const bytesCache = await createCache({ capacity: 1000 });
|
|
200
|
+
bytesCache.setBytes('image', new Uint8Array(buffer), { ttlMs: 30_000 });
|
|
201
|
+
const view = bytesCache.getBytes('image'); // Uint8Array view onto Wasm memory
|
|
202
|
+
const copy = bytesCache.getBytesCopy('image'); // owned snapshot, safe to retain
|
|
203
|
+
// set()/get() still work on the same cache and are unchanged.
|
|
204
|
+
|
|
205
|
+
// 2. Values live in a JS Map; Wasm keeps metadata + stable ids.
|
|
206
|
+
const hybrid = await createCache({ capacity: 1000, storage: 'js' });
|
|
207
|
+
hybrid.set('user:42', user, { tags: ['user'] }); // value stays in JS
|
|
208
|
+
hybrid.get('user:42'); // Wasm by id, then Map.get — same reference
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Bytes mode** copies the payload once into an arena region, then hands out a view with no
|
|
212
|
+
second copy. A view is valid only until the next allocation: `memory.grow` detaches the old
|
|
213
|
+
`ArrayBuffer`, and an evicted region can be reused. Use `getBytesCopy` for anything long-lived.
|
|
214
|
+
`entries()`/`entry()` and persistence see a copied `Uint8Array`, so those paths stay
|
|
215
|
+
structured-cloneable. `setBytes` is unavailable with `storage: 'js'` and throws a clear error.
|
|
216
|
+
Advanced producers that already wrote into the arena can call
|
|
217
|
+
`cache.setBytesReserved(key, ptr, len, options?)` to adopt the region with no JS→Wasm copy;
|
|
218
|
+
get `ptr` from `WasmCache.bytesReserve(len)` (exported from the wasm package) and write through a
|
|
219
|
+
view of `wasmLinearMemory().buffer`. The public `setBytes` and its view-lifetime contract are
|
|
220
|
+
unchanged.
|
|
221
|
+
|
|
222
|
+
**`storage: 'js'`** preserves by-reference semantics, tag invalidation, events, statistics,
|
|
223
|
+
`entry()`/`entries()` and persistence: Wasm still owns the policy and reports evictions by
|
|
224
|
+
stable id, and the JS layer deletes the corresponding value from its `Map` (the `evict`/`expire`
|
|
225
|
+
events carry the real value, exactly as in the default mode). The cost is one extra `Map` lookup
|
|
226
|
+
per read and an extra `Map` write per set — the key scratch buffer already makes the default
|
|
227
|
+
path cheap, so **measure before enabling** (see the published deltas linked from the root
|
|
228
|
+
README). Both modes are strictly opt-in; a cache created with no options is byte-for-byte the
|
|
229
|
+
same implementation as before.
|
|
230
|
+
|
|
144
231
|
## Good to know
|
|
145
232
|
|
|
146
|
-
|
|
233
|
+
- **The `.wasm` ships inside this package** — no CDN setup, no separate asset download.
|
|
147
234
|
`createCache` fetches it relative to the package's own module, streams it in, and does
|
|
148
235
|
it once per page even when several caches are created at once. Under Vite this needs no
|
|
149
236
|
configuration at all.
|
|
@@ -162,31 +249,31 @@ stop(); stopMany(); stopTag(); // idempotent — also safe from inside a
|
|
|
162
249
|
two at once throws a `TypeError`. Failures name the URL or step that failed and keep the
|
|
163
250
|
original error on `cause`.
|
|
164
251
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
252
|
+
- **Types are bundled** — no `@types/*` packages to install.
|
|
253
|
+
- **ESM only, browser only.** Node/SSR targets are out of scope by design.
|
|
254
|
+
- **Values are shared by reference** — `set` hands the object over and `get`/`peek`/
|
|
168
255
|
`entry` hand the same object back, so mutating it rewrites the cache (and, after the
|
|
169
256
|
next flush, the persisted row). Clone on the way out if you need to edit: the sharing
|
|
170
257
|
is what keeps `get`/`set` allocation-free.
|
|
171
|
-
|
|
258
|
+
- **Persistence is optional** and off by default; a blocked IndexedDB (private mode)
|
|
172
259
|
degrades to memory-only instead of breaking the app. A flush that fails later — a quota
|
|
173
260
|
error, a transient IndexedDB problem — is reported (`onError`, or the awaited call's
|
|
174
261
|
rejection) and its records go straight back on the queue for the next flush, rather
|
|
175
|
-
than being dropped; the exception is a record that fails
|
|
262
|
+
than being dropped; the exception is a record that fails _on its own_ three times
|
|
176
263
|
running, which is dropped from the queue with a console warning (still in memory) so one
|
|
177
264
|
poison row cannot block every later flush, and any successful pass resets the count.
|
|
178
265
|
Options — `namespace`, `debounceMs`, `maxEntries`, `restoreExpired`, `writeMode`,
|
|
179
266
|
`onError`, `onActivity`, `generation` — are validated when persistence is attached and
|
|
180
|
-
throw from `
|
|
267
|
+
throw from `createCache()` rather than misbehave later (`flushDelayMs`/`maxRecords` remain as
|
|
181
268
|
aliases). `cache.persistence` is the control surface: `flush()` writes now, `clear()`
|
|
182
269
|
empties storage without touching memory, `hydrate()` reloads storage into memory,
|
|
183
270
|
`stats()` reports counters, and `rotate(generation)` switches sessions — dropping the
|
|
184
|
-
previous session's queued
|
|
271
|
+
previous session's queued _and_ in-flight writes (see
|
|
185
272
|
[Persistence](https://github.com/blaze-cache/blaze-cache#persistence)).
|
|
186
|
-
|
|
273
|
+
- **`capacity` is normalised** — below `1` clamps up, above `1_000_000` clamps down, and
|
|
187
274
|
a non-finite value falls back to the wasm default — so `capacity()` reports a real
|
|
188
275
|
number back.
|
|
189
|
-
|
|
276
|
+
- **Events cost nothing when unused** — with no listeners the bus is a size check per
|
|
190
277
|
operation, and the Rust core's drop log stays off until somebody asks for
|
|
191
278
|
`evict`/`expire`, or subscribes to a key or a tag (see [Events](#events) and
|
|
192
279
|
[Subscriptions](#subscriptions)).
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BlazeCacheLike, CacheEntry, CacheEventListener, CacheEventType, CacheKeySubscriber, CacheListener, CacheManySubscriber, CacheStats, CacheSubscribeOptions, CacheTagSubscriber, SetManyEntry, SetOptions, TouchOptions } from './types.js';
|
|
2
|
+
import type { QueryKeysResult as QueryKeysPage, QueryOptions, QueryResult } from './query.js';
|
|
3
|
+
import type { MultiTabOptions } from './multitab.js';
|
|
2
4
|
import type { WasmLoadOptions } from './wasm.js';
|
|
3
5
|
import type { CachePersistence, PersistenceControl, PersistenceOptions } from './persistence/types.js';
|
|
4
6
|
/** Entries held when `capacity` is not given. */
|
|
@@ -39,6 +41,29 @@ export interface BlazeCacheOptions extends WasmLoadOptions {
|
|
|
39
41
|
* {@link BlazeCache.persistence}.
|
|
40
42
|
*/
|
|
41
43
|
persistence?: false | CachePersistenceOptions | IndexedDbPersistenceOptions;
|
|
44
|
+
/**
|
|
45
|
+
* Opt-in cross-tab synchronization over `BroadcastChannel`. Off by default; a cache created
|
|
46
|
+
* without it behaves exactly as before. See {@link MultiTabOptions}.
|
|
47
|
+
*/
|
|
48
|
+
multiTab?: MultiTabOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Where values live. `wasm` (default) keeps the current by-reference externref contract:
|
|
51
|
+
* the value is stored in the Rust slab and every read crosses the Wasm boundary.
|
|
52
|
+
*
|
|
53
|
+
* `js` is an **opt-in** hybrid: wasm keeps keys, TTL, tags, SIEVE and stable entry ids, while
|
|
54
|
+
* values live in a JS `Map<id, V>`. Hot reads call wasm by id (no key string marshalled) and
|
|
55
|
+
* then look the value up locally. By-reference semantics, tag invalidation, events,
|
|
56
|
+
* persistence and `entry()`/`entries()` behave identically; only the ownership of values
|
|
57
|
+
* moves from the slab to JS. Feature is off unless you ask for it.
|
|
58
|
+
*/
|
|
59
|
+
storage?: 'wasm' | 'js';
|
|
60
|
+
/**
|
|
61
|
+
* Opt in to the ordered key/tag/expiry indexes used by {@link BlazeCache.query}.
|
|
62
|
+
* Off by default: an opted-out cache allocates no index and its write path is unchanged.
|
|
63
|
+
* Without this, `query()` throws a setup error (an explicit `fullScan` is required to
|
|
64
|
+
* read through the whole cache instead).
|
|
65
|
+
*/
|
|
66
|
+
indexes?: boolean;
|
|
42
67
|
}
|
|
43
68
|
/** The options {@link createCache} takes — an alias for {@link BlazeCacheOptions}. */
|
|
44
69
|
export type CreateCacheOptions = BlazeCacheOptions;
|
|
@@ -217,6 +242,18 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
217
242
|
capacity(): number;
|
|
218
243
|
/** Cumulative counters plus a computed `hitRate`. */
|
|
219
244
|
stats(): CacheStats;
|
|
245
|
+
/**
|
|
246
|
+
* Bounded, indexed query. Returns metadata only unless `includeValues` is set (which
|
|
247
|
+
* requires both caps and hands back live by-reference values).
|
|
248
|
+
*
|
|
249
|
+
* Throws a setup error without `createCache({ indexes: true })`; an explicit
|
|
250
|
+
* `fullScan: true` with no other constraints is the only O(n) path.
|
|
251
|
+
*/
|
|
252
|
+
query<V2 = V>(filter: QueryOptions): QueryResult<V2>;
|
|
253
|
+
/** Key-only form of {@link BlazeCache.query}, with the same cursor semantics. */
|
|
254
|
+
queryKeys(filter: QueryOptions): QueryKeysPage;
|
|
255
|
+
/** Number of matching entries. Requires `indexes: true`; never an implicit full scan. */
|
|
256
|
+
count(filter?: Omit<QueryOptions, 'limit' | 'cursor'>): number;
|
|
220
257
|
/**
|
|
221
258
|
* Stores (or replaces) `key`. Replacing refreshes the TTL and replaces the tags.
|
|
222
259
|
*
|
|
@@ -233,6 +270,36 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
233
270
|
* Listeners are notified for each entry when change consumers exist.
|
|
234
271
|
*/
|
|
235
272
|
setMany(entries: SetManyEntry<V>[]): void;
|
|
273
|
+
/**
|
|
274
|
+
* Stores raw bytes **directly in Wasm linear memory** and reads them back as a zero-copy
|
|
275
|
+
* `Uint8Array` view. Only available in the default `storage: 'wasm'` mode.
|
|
276
|
+
*
|
|
277
|
+
* The payload is copied once into a reserved arena region (a raw byte copy, not JS object
|
|
278
|
+
* serialisation); `getBytes` then returns a view onto that region with no copy at all. This
|
|
279
|
+
* is the only genuine zero-copy value path, because arbitrary JS objects cannot live in
|
|
280
|
+
* linear memory. Prefer `getBytesCopy` when a view must outlive the next write or eviction.
|
|
281
|
+
*/
|
|
282
|
+
setBytes(key: string, value: ArrayBufferView | ArrayBuffer, options?: SetOptions): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* A zero-copy view of a byte value, or `undefined` when the key is missing or was written
|
|
285
|
+
* with `set`. Counts a hit/miss exactly like {@link BlazeCache.get}.
|
|
286
|
+
*
|
|
287
|
+
* The view is valid until the next Wasm allocation: `memory.grow` detaches the old
|
|
288
|
+
* `ArrayBuffer`, and an evicted region may be reused. Read it promptly, or use
|
|
289
|
+
* {@link BlazeCache.getBytesCopy} for a long-lived snapshot.
|
|
290
|
+
*/
|
|
291
|
+
getBytes(key: string): Uint8Array | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Advanced bytes-producer path: stores an already-reserved arena region by its `(ptr, len)`
|
|
294
|
+
* coordinates, with no JS→Wasm copy. Obtain `ptr` from `WasmCache.bytesReserve(len)` and write
|
|
295
|
+
* the payload into `new Uint8Array(wasmLinearMemory().buffer, ptr, len)` first — a decoder can
|
|
296
|
+
* therefore write straight into Wasm memory and hand the region to the cache. A rejected or
|
|
297
|
+
* stale pointer stores nothing and returns `false`. The public `setBytes` remains the safe
|
|
298
|
+
* default; this entry point is opt-in and shares its view-lifetime contract.
|
|
299
|
+
*/
|
|
300
|
+
setBytesReserved(key: string, ptr: number, length: number, options?: SetOptions): boolean;
|
|
301
|
+
/** An owned copy of a byte value — safe to retain across writes, eviction and `memory.grow`. */
|
|
302
|
+
getBytesCopy(key: string): Uint8Array | undefined;
|
|
236
303
|
/**
|
|
237
304
|
* Marks `key` as recently used for eviction and optionally renews its TTL — the stored
|
|
238
305
|
* value is never changed.
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EAEV,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,YAAY,EACb,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,KAAK,EACV,gBAAgB,EAGhB,kBAAkB,EAElB,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