@blaze-cache/core 0.2.0-beta → 0.2.3-beta
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 +67 -4
- package/dist/cache.d.ts +190 -11
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +419 -60
- package/dist/cache.js.map +1 -1
- package/dist/events.d.ts +84 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +179 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/persistence/indexeddb.d.ts.map +1 -1
- package/dist/persistence/indexeddb.js +19 -0
- package/dist/persistence/indexeddb.js.map +1 -1
- package/dist/persistence/types.d.ts +12 -0
- package/dist/persistence/types.d.ts.map +1 -1
- package/dist/types.d.ts +130 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/pkg/blaze_cache_wasm.d.ts +63 -1
- package/pkg/blaze_cache_wasm.js +179 -1
- package/pkg/blaze_cache_wasm_bg.wasm +0 -0
- package/pkg/blaze_cache_wasm_bg.wasm.d.ts +7 -0
- package/pkg/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,16 +8,20 @@ WebAssembly client-side cache for the browser: SIEVE eviction, per-entry TTLs, t
|
|
|
8
8
|
invalidation and optional IndexedDB persistence.
|
|
9
9
|
|
|
10
10
|
The engine behind
|
|
11
|
-
[`@blaze-cache/axios`](https://www.npmjs.com/package/@blaze-cache/axios)
|
|
11
|
+
[`@blaze-cache/axios`](https://www.npmjs.com/package/@blaze-cache/axios),
|
|
12
|
+
[`@blaze-cache/fetch`](https://www.npmjs.com/package/@blaze-cache/fetch) and
|
|
12
13
|
[`@blaze-cache/react-query`](https://www.npmjs.com/package/@blaze-cache/react-query) —
|
|
13
14
|
also usable on its own.
|
|
14
15
|
|
|
15
16
|
## Install
|
|
16
17
|
|
|
17
18
|
```sh
|
|
18
|
-
npm install @blaze-cache/core
|
|
19
|
+
npm install @blaze-cache/core@beta
|
|
19
20
|
```
|
|
20
21
|
|
|
22
|
+
`@beta` is npm's dist-tag for the prerelease; drop it to install the last stable
|
|
23
|
+
release.
|
|
24
|
+
|
|
21
25
|
## Quick start
|
|
22
26
|
|
|
23
27
|
```ts
|
|
@@ -38,6 +42,53 @@ cache.stats(); // { hits, misses, evictions, expirations,
|
|
|
38
42
|
`create` instantiates the wasm module once, so everything after it is **synchronous** —
|
|
39
43
|
`get`/`set` never allocate a `Promise`.
|
|
40
44
|
|
|
45
|
+
## Events
|
|
46
|
+
|
|
47
|
+
Everything the cache does is observable through a typed event system. `on(type, listener)`
|
|
48
|
+
subscribes to one event type, `on(listener)` subscribes to **all** of them (wildcard), both
|
|
49
|
+
return their own unsubscribe function, and `once` / `off` complete the API:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// One event type — the payload is typed to exactly that event.
|
|
53
|
+
const offEvict = cache.on('evict', ({ key, value }) => {
|
|
54
|
+
console.log('the cache dropped', key, value);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Wildcard: every event, payload the full union (narrow on `event.type`).
|
|
58
|
+
cache.on((event) => {
|
|
59
|
+
if (event.type === 'hit') console.log('hit', event.key, event.value);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
cache.once('clear', () => console.log('first clear, only once'));
|
|
63
|
+
|
|
64
|
+
cache.off('evict'); // every `evict` listener
|
|
65
|
+
cache.off(); // every listener, period
|
|
66
|
+
offEvict(); // …or just this one handle (idempotent)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Event | Emitted when | Payload |
|
|
70
|
+
| --- | --- | --- |
|
|
71
|
+
| `set` | a key was stored (insert or replace) | `key` |
|
|
72
|
+
| `delete` | a key was removed and was present | `key` |
|
|
73
|
+
| `clear` | the cache was emptied | — |
|
|
74
|
+
| `invalidate` | `invalidateTags()` removed entries | `keys` |
|
|
75
|
+
| `prune` | `prune()` removed expired entries | `keys` |
|
|
76
|
+
| `touch` | `touch()` renewed a live entry's deadline | `key` |
|
|
77
|
+
| `evict` | the core dropped an entry to stay within capacity | `key`, `value` |
|
|
78
|
+
| `expire` | the core reclaimed an entry whose TTL elapsed | `key`, `value` |
|
|
79
|
+
| `hit` | `get()` / `getMany()` found a live entry | `key`, `value` |
|
|
80
|
+
| `miss` | a lookup found nothing (absent or expired) | `key` |
|
|
81
|
+
|
|
82
|
+
Eight of those are raised in TypeScript around the call you made; `evict` and `expire`
|
|
83
|
+
happen *inside* the Rust core and are delivered from an opt-in **drop log** — the first
|
|
84
|
+
listener interested in them switches it on through the wasm binding, and with no such
|
|
85
|
+
listener the hot path pays a single predictable branch. Listeners run synchronously in
|
|
86
|
+
registration order (typed first, wildcards last), a throwing listener is logged and
|
|
87
|
+
skipped — never able to undo a mutation — and reads that record nothing (`peek`, `has`,
|
|
88
|
+
`ttl`, `size`, `keys`, `entry`) emit nothing. `dispose()` clears every listener along with
|
|
89
|
+
the wasm memory. The full design notes live in the
|
|
90
|
+
[repository README](https://github.com/blaze-cache/blaze-cache#events).
|
|
91
|
+
|
|
41
92
|
## Good to know
|
|
42
93
|
|
|
43
94
|
* **The `.wasm` ships inside this package** — no CDN setup. If your bundler
|
|
@@ -51,12 +102,24 @@ cache.stats(); // { hits, misses, evictions, expirations,
|
|
|
51
102
|
|
|
52
103
|
* **Types are bundled** — no `@types/*` packages to install.
|
|
53
104
|
* **ESM only, browser only.** Node/SSR targets are out of scope by design.
|
|
105
|
+
* **Values are shared by reference** — `set` hands the object over and `get`/`peek`/
|
|
106
|
+
`entry` hand the same object back, so mutating it rewrites the cache (and, after the
|
|
107
|
+
next flush, the persisted row). Clone on the way out if you need to edit: the sharing
|
|
108
|
+
is what keeps `get`/`set` allocation-free.
|
|
54
109
|
* **Persistence is optional** and off by default; a blocked IndexedDB (private mode)
|
|
55
|
-
degrades to memory-only instead of breaking the app.
|
|
110
|
+
degrades to memory-only instead of breaking the app. A flush that fails later — a quota
|
|
111
|
+
error, a transient IndexedDB problem — is logged and its records go straight back on
|
|
112
|
+
the queue for the next flush, rather than being dropped.
|
|
113
|
+
* **`capacity` is normalised** — below `1` clamps up, above `1_000_000` clamps down, and
|
|
114
|
+
a non-finite value falls back to the wasm default — so `capacity()` reports a real
|
|
115
|
+
number back.
|
|
116
|
+
* **Events cost nothing when unused** — with no listeners the bus is a size check per
|
|
117
|
+
operation, and the Rust core's drop log stays off until somebody asks for
|
|
118
|
+
`evict`/`expire` (see [Events](#events)).
|
|
56
119
|
|
|
57
120
|
## Documentation
|
|
58
121
|
|
|
59
|
-
Setup, persistence, eviction, tags and the full API are documented in the
|
|
122
|
+
Setup, persistence, eviction, tags, events and the full API are documented in the
|
|
60
123
|
[repository README](https://github.com/blaze-cache/blaze-cache#readme).
|
|
61
124
|
|
|
62
125
|
## License
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlazeCacheLike, CacheEntry, CacheListener, CacheStats, SetOptions, TouchOptions } from './types.js';
|
|
1
|
+
import type { BlazeCacheLike, CacheEntry, CacheEventListener, CacheEventType, CacheListener, CacheStats, SetManyEntry, SetOptions, TouchOptions } from './types.js';
|
|
2
2
|
import type { WasmInitInput } from './wasm.js';
|
|
3
3
|
import type { CachePersistence, IndexedDbOptions } from './persistence/types.js';
|
|
4
4
|
/** Entries held when `capacity` is not given. */
|
|
@@ -22,7 +22,14 @@ export interface IndexedDbPersistenceOptions extends IndexedDbOptions {
|
|
|
22
22
|
}
|
|
23
23
|
/** Options accepted by {@link BlazeCache.create}. */
|
|
24
24
|
export interface BlazeCacheOptions {
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Maximum number of entries kept in memory. The wasm binding normalises it before it is
|
|
27
|
+
* ever used: below `1` clamps up, above `1_000_000` clamps down, and a non-finite value
|
|
28
|
+
* (`NaN`, `Infinity`) falls back to the wasm default of 1024. Pass a value inside that
|
|
29
|
+
* range to be sure of what {@link BlazeCache.capacity} reports back.
|
|
30
|
+
*
|
|
31
|
+
* Default {@link DEFAULT_CAPACITY}.
|
|
32
|
+
*/
|
|
26
33
|
capacity?: number;
|
|
27
34
|
/**
|
|
28
35
|
* Durable storage. `false`/omitted means memory only.
|
|
@@ -55,6 +62,77 @@ export interface BlazeCacheOptions {
|
|
|
55
62
|
* await cache.dispose();
|
|
56
63
|
* ```
|
|
57
64
|
*
|
|
65
|
+
* ### Value ownership
|
|
66
|
+
*
|
|
67
|
+
* Values are held — and handed back — **by reference**. The object you pass to
|
|
68
|
+
* {@link BlazeCache.set} is the very object {@link BlazeCache.get}, {@link BlazeCache.peek},
|
|
69
|
+
* {@link BlazeCache.entry} and {@link BlazeCache.entries} return later: mutating either one
|
|
70
|
+
* silently rewrites the cache — and, after the next flush, the persisted row — with no error
|
|
71
|
+
* and no warning. Treat values living in the cache as read-only: clone on the way *out*
|
|
72
|
+
* (`structuredClone(cache.get(key))`) before editing, or clone on the way *in* if you want
|
|
73
|
+
* to keep mutating your own copy. The sharing is deliberate, not an oversight — the Rust
|
|
74
|
+
* core promises allocation-free `get`/`set` precisely *because* values are never cloned or
|
|
75
|
+
* serialised on the hot path, and cloning on read would only close one half of the alias
|
|
76
|
+
* anyway (your original reference from `set` survives either way). The contract is
|
|
77
|
+
* ownership transfer, not deep-copy semantics.
|
|
78
|
+
*
|
|
79
|
+
* ### Events
|
|
80
|
+
*
|
|
81
|
+
* {@link BlazeCache.on} subscribes to one {@link CacheEventType} — `on('set', listener)` —
|
|
82
|
+
* or, without a type, to **every** event; `once` fires a single time, `off` removes
|
|
83
|
+
* listeners without a subscription handle, and every `on`/`once` call returns its own
|
|
84
|
+
* unsubscribe function.
|
|
85
|
+
*
|
|
86
|
+
* Eight event types are raised here in TypeScript, describing the operation you just made.
|
|
87
|
+
* `evict` and `expire` are the exception: capacity sweeps and TTL reclamation happen
|
|
88
|
+
* *inside* the Rust core — mid-`set`, or lazily during a `get` — where no JavaScript
|
|
89
|
+
* exists to observe them. For those the core keeps an opt-in **drop log**. The first
|
|
90
|
+
* listener interested in `evict`/`expire` (a typed one, or any wildcard) switches the log
|
|
91
|
+
* on through the wasm binding, and after every operation that can reclaim memory (`get`,
|
|
92
|
+
* `getMany`, `set`, `setMany`) this class drains it and emits one event per dropped entry:
|
|
93
|
+
* `{ type: 'evict' | 'expire', key, value }`, with `value` coming back as the cache's live
|
|
94
|
+
* reference — exactly what you would have got from `get` one moment earlier. While no such
|
|
95
|
+
* listener exists the log stays off and the hot path pays a single predictable branch at
|
|
96
|
+
* the moment an entry dies — never per read or write.
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* const offEvict = cache.on('evict', ({ key, value }) => {
|
|
100
|
+
* console.log('the cache dropped', key, value);
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* const offAll = cache.on((event) => { // wildcard — every event type
|
|
104
|
+
* if (event.type === 'hit') console.log('hit', event.key);
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* cache.once('clear', () => console.log('first clear, only once'));
|
|
108
|
+
*
|
|
109
|
+
* offEvict(); // unsubscribe one handle
|
|
110
|
+
* cache.off('evict'); // …or drop every `evict` listener
|
|
111
|
+
* cache.off(); // …or every listener, period
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* Wildcard listeners receive the full {@link CacheEvent} union, so narrow on
|
|
115
|
+
* `event.type` before reading fields. A listener that throws is isolated: the failure is
|
|
116
|
+
* logged with `console.error`, the mutation it was told about stands, and the remaining
|
|
117
|
+
* listeners still run. Listeners run synchronously, in registration order per type (typed
|
|
118
|
+
* listeners first, wildcards last) — an event is never delivered to a listener that
|
|
119
|
+
* unsubscribed before its turn.
|
|
120
|
+
*
|
|
121
|
+
* Code written against the original `on(listener)` API keeps working: that form *is* the
|
|
122
|
+
* wildcard now, so such listeners additionally see `hit`/`miss`/`evict`/`expire`.
|
|
123
|
+
*
|
|
124
|
+
* ### Multiple tabs
|
|
125
|
+
*
|
|
126
|
+
* Tabs share one IndexedDB namespace but nothing else: each one holds its own WebAssembly
|
|
127
|
+
* instance, hydrated once at startup, and each flushes the keys it wrote. There is no
|
|
128
|
+
* coordination between them — writes are last-writer-wins per key. For ordinary use that is
|
|
129
|
+
* what you want (the tab in the foreground refetches on focus and rewrites its own fresh
|
|
130
|
+
* copy), but a tab that keeps working while hidden — a timer, a background sync — can flush
|
|
131
|
+
* a value older than the one the focused tab just wrote, and after a reload that older
|
|
132
|
+
* value is what hydration paints until revalidation corrects it. If that matters, use a
|
|
133
|
+
* short `ttlMs` on records written from background tabs, or filter on a timestamp you store
|
|
134
|
+
* inside the value itself.
|
|
135
|
+
*
|
|
58
136
|
* All reads and writes are synchronous — the wasm module is instantiated during `create`, so
|
|
59
137
|
* the hot path never touches a `Promise`.
|
|
60
138
|
*/
|
|
@@ -68,14 +146,30 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
68
146
|
* console warning instead of rejecting.
|
|
69
147
|
*/
|
|
70
148
|
static create<V = any>(options?: BlazeCacheOptions): Promise<BlazeCache<V>>;
|
|
71
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Value stored under `key`, or `undefined` when missing or expired. Counts a hit/miss.
|
|
151
|
+
*
|
|
152
|
+
* The value comes back as the cache's **live reference** — see *Value ownership* on the
|
|
153
|
+
* class before mutating it. Emits {@link CacheEventMap.hit} / {@link CacheEventMap.miss}
|
|
154
|
+
* when someone listens, and an entry whose stored value *is* `undefined` counts as a
|
|
155
|
+
* miss — from the caller's side there is no way to tell it apart from absence anyway.
|
|
156
|
+
*/
|
|
72
157
|
get(key: string): V | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Batch lookup: returns the value for each key, or `undefined` when missing/expired.
|
|
160
|
+
* Crosses the wasm boundary once instead of once per key.
|
|
161
|
+
*
|
|
162
|
+
* Each hit marks the entry visited for SIEVE, exactly like {@link BlazeCache.get} — and
|
|
163
|
+
* emits one `hit`/`miss` event per key.
|
|
164
|
+
*/
|
|
165
|
+
getMany(keys: string[]): (V | undefined)[];
|
|
73
166
|
/**
|
|
74
167
|
* The same lookup as {@link BlazeCache.get}, minus every side effect: no hit or miss is
|
|
75
168
|
* recorded, the entry is not marked used for eviction, and nothing is reclaimed.
|
|
76
169
|
*
|
|
77
170
|
* The read for "is this here?" questions — a UI check must not be able to move the hit
|
|
78
|
-
* rate or decide who gets evicted next.
|
|
171
|
+
* rate or decide who gets evicted next. The value is still the cache's **live reference**,
|
|
172
|
+
* exactly like {@link BlazeCache.get}.
|
|
79
173
|
*/
|
|
80
174
|
peek(key: string): V | undefined;
|
|
81
175
|
/**
|
|
@@ -88,9 +182,20 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
88
182
|
ttl(key: string): number | undefined;
|
|
89
183
|
/** `true` when `key` is present and not expired. Never changes eviction state. */
|
|
90
184
|
has(key: string): boolean;
|
|
91
|
-
/**
|
|
185
|
+
/**
|
|
186
|
+
* Batch existence check: returns `true` for each key that is present and not expired.
|
|
187
|
+
* Crosses the wasm boundary once instead of once per key.
|
|
188
|
+
*/
|
|
189
|
+
hasMany(keys: string[]): boolean[];
|
|
190
|
+
/**
|
|
191
|
+
* Live entry — value, remaining TTL and tags — without touching statistics. The `value`
|
|
192
|
+
* field is the cache's live reference — see *Value ownership* on the class.
|
|
193
|
+
*/
|
|
92
194
|
entry(key: string): CacheEntry<V> | undefined;
|
|
93
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* Snapshot of every live entry, oldest first. The `value` fields are the cache's live
|
|
197
|
+
* references — see *Value ownership* on the class.
|
|
198
|
+
*/
|
|
94
199
|
entries(): CacheEntry<V>[];
|
|
95
200
|
/** Live keys, oldest first. */
|
|
96
201
|
keys(): string[];
|
|
@@ -111,8 +216,22 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
111
216
|
capacity(): number;
|
|
112
217
|
/** Cumulative counters plus a computed `hitRate`. */
|
|
113
218
|
stats(): CacheStats;
|
|
114
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Stores (or replaces) `key`. Replacing refreshes the TTL and replaces the tags.
|
|
221
|
+
*
|
|
222
|
+
* The value is stored **by reference** — the cache takes ownership for the lifetime of the
|
|
223
|
+
* entry, so mutating it afterwards rewrites the cache (see *Value ownership* on the class).
|
|
224
|
+
*/
|
|
115
225
|
set(key: string, value: V, options?: SetOptions): void;
|
|
226
|
+
/**
|
|
227
|
+
* Batch write: stores every key/value pair in one wasm boundary crossing.
|
|
228
|
+
*
|
|
229
|
+
* Each entry's `ttlMs` and `tags` are applied independently. A negative `ttlMs` means
|
|
230
|
+
* "no expiry". Crosses the boundary once instead of once per entry.
|
|
231
|
+
*
|
|
232
|
+
* Listeners are notified for each entry when change consumers exist.
|
|
233
|
+
*/
|
|
234
|
+
setMany(entries: SetManyEntry<V>[]): void;
|
|
116
235
|
/**
|
|
117
236
|
* Marks `key` as recently used for eviction and optionally renews its TTL — the stored
|
|
118
237
|
* value is never changed.
|
|
@@ -124,6 +243,11 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
124
243
|
touch(key: string, options?: TouchOptions): boolean;
|
|
125
244
|
/** Removes `key`, returning whether it was there. */
|
|
126
245
|
delete(key: string): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Batch delete: removes every key, returning `true` for each key that was present.
|
|
248
|
+
* Crosses the wasm boundary once instead of once per key.
|
|
249
|
+
*/
|
|
250
|
+
deleteMany(keys: string[]): boolean[];
|
|
127
251
|
/** Removes every entry carrying any of `tags`, returning the removed keys. */
|
|
128
252
|
invalidateTags(...tags: string[]): string[];
|
|
129
253
|
/** Removes every expired entry, returning the removed keys. */
|
|
@@ -133,24 +257,79 @@ export declare class BlazeCache<V = any> implements BlazeCacheLike<V> {
|
|
|
133
257
|
/** Zeroes the cumulative counters without touching stored entries. */
|
|
134
258
|
resetStats(): void;
|
|
135
259
|
/**
|
|
136
|
-
* Subscribes to
|
|
260
|
+
* Subscribes to cache events. Returns the unsubscribe function.
|
|
261
|
+
*
|
|
262
|
+
* Two forms:
|
|
263
|
+
*
|
|
264
|
+
* * `on(type, listener)` — only events of that {@link CacheEventType}; the payload is
|
|
265
|
+
* typed to exactly that event.
|
|
266
|
+
* * `on(listener)` — **wildcard**: every event, payload the full {@link CacheEvent}
|
|
267
|
+
* union (narrow on `event.type` to read per-event fields).
|
|
137
268
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
269
|
+
* Registering the same function twice for the same type is a no-op, and the returned
|
|
270
|
+
* unsubscribe function is idempotent. Persistence uses listeners internally, so
|
|
271
|
+
* bookkeeping runs for every change regardless of whether anyone subscribed; a listener
|
|
272
|
+
* that throws is isolated — the failure is logged with `console.error`, the mutation it
|
|
273
|
+
* was told about stands, and the remaining listeners are still notified.
|
|
274
|
+
*
|
|
275
|
+
* Subscribing to `evict`/`expire` (or to anything via the wildcard) switches on the Rust
|
|
276
|
+
* core's drop log — see *Events* on the class. Unsubscribing the last such listener
|
|
277
|
+
* switches it off again.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* const off = cache.on('set', ({ key }) => console.log('stored', key));
|
|
282
|
+
* const offAll = cache.on((event) => console.log(event.type));
|
|
283
|
+
* off();
|
|
284
|
+
* ```
|
|
140
285
|
*/
|
|
286
|
+
on<K extends CacheEventType>(type: K, listener: CacheEventListener<V, K>): () => void;
|
|
287
|
+
on(listener: CacheEventListener<V>): () => void;
|
|
288
|
+
/** @deprecated The pre-event-system signature — kept so old annotations still compile. */
|
|
141
289
|
on(listener: CacheListener): () => void;
|
|
290
|
+
/**
|
|
291
|
+
* Like {@link BlazeCache.on}, but the listener fires at most once — it is removed as it
|
|
292
|
+
* runs, so a re-entrant emit from inside it cannot deliver a second time. Returns the
|
|
293
|
+
* unsubscribe function, which simply becomes a no-op after the fire.
|
|
294
|
+
*/
|
|
295
|
+
once<K extends CacheEventType>(type: K, listener: CacheEventListener<V, K>): () => void;
|
|
296
|
+
once(listener: CacheEventListener<V>): () => void;
|
|
297
|
+
/** @deprecated The pre-event-system signature — kept so old annotations still compile. */
|
|
298
|
+
once(listener: CacheListener): () => void;
|
|
299
|
+
/**
|
|
300
|
+
* Removes listeners without needing the unsubscribe handle:
|
|
301
|
+
*
|
|
302
|
+
* * `off()` — every listener of every type;
|
|
303
|
+
* * `off(type)` — every listener of that type;
|
|
304
|
+
* * `off(type, listener)` — that one registration;
|
|
305
|
+
* * `off(listener)` — that function from the wildcard **and** every typed set.
|
|
306
|
+
*
|
|
307
|
+
* Calling it with something that is not registered is a no-op. Releasing the last
|
|
308
|
+
* `evict`/`expire`-interested listener also switches the core's drop log off.
|
|
309
|
+
*/
|
|
310
|
+
off(): void;
|
|
311
|
+
off(type: CacheEventType): void;
|
|
312
|
+
off(type: CacheEventType, listener: CacheEventListener<V>): void;
|
|
313
|
+
off(listener: CacheEventListener<V> | CacheListener): void;
|
|
142
314
|
/**
|
|
143
315
|
* Writes pending changes to storage immediately.
|
|
144
316
|
*
|
|
145
317
|
* Resolves once the underlying transaction commits. Concurrent calls are serialised, so
|
|
146
318
|
* this is safe to call from a `beforeunload` handler while a debounced flush is pending.
|
|
319
|
+
*
|
|
320
|
+
* When the write itself fails — quota, a blocked or transient IndexedDB error — the pass
|
|
321
|
+
* rejects **and hands every record it had claimed back onto the queue**, so the next flush
|
|
322
|
+
* (a later mutation's timer, an explicit call, `pagehide`, `dispose`) retries them instead
|
|
323
|
+
* of losing them.
|
|
147
324
|
*/
|
|
148
325
|
flush(): Promise<void>;
|
|
149
326
|
/**
|
|
150
327
|
* Flushes, unbinds page-lifecycle listeners and frees the wasm memory.
|
|
151
328
|
*
|
|
152
329
|
* The cache is unusable afterwards. A failed flush still rejects — the caller may retry or
|
|
153
|
-
* report it
|
|
330
|
+
* report it — but teardown happens in a `finally`, so a storage outage can never leak the
|
|
331
|
+
* wasm instance, the timers or the `pagehide`/`visibilitychange` listeners behind a
|
|
332
|
+
* rejected promise.
|
|
154
333
|
*/
|
|
155
334
|
dispose(): Promise<void>;
|
|
156
335
|
}
|
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,
|
|
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,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACb,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAmB,MAAM,wBAAwB,CAAC;AAElG,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,wDAAwD;AACxD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAUxC,6DAA6D;AAC7D,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,gBAAgB,CAAC;IAC1B,yFAAyF;IACzF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,6FAA6F;IAC7F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,+EAA+E;AAC/E,MAAM,WAAW,2BAA4B,SAAQ,gBAAgB;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qDAAqD;AACrD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,KAAK,GAA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