swr-redis 0.0.0-stage → 1.0.0

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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -2
  3. package/dist/cache.d.ts +35 -0
  4. package/dist/cache.d.ts.map +1 -0
  5. package/dist/cache.js +464 -0
  6. package/dist/cache.js.map +1 -0
  7. package/dist/client.d.ts +23 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +69 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/codec.d.ts +20 -0
  12. package/dist/codec.d.ts.map +1 -0
  13. package/dist/codec.js +35 -0
  14. package/dist/codec.js.map +1 -0
  15. package/dist/errors.d.ts +23 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +45 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/events.d.ts +12 -0
  20. package/dist/events.d.ts.map +1 -0
  21. package/dist/events.js +42 -0
  22. package/dist/events.js.map +1 -0
  23. package/dist/index.d.ts +5 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +4 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/keys.d.ts +7 -0
  28. package/dist/keys.d.ts.map +1 -0
  29. package/dist/keys.js +17 -0
  30. package/dist/keys.js.map +1 -0
  31. package/dist/lock.d.ts +36 -0
  32. package/dist/lock.d.ts.map +1 -0
  33. package/dist/lock.js +119 -0
  34. package/dist/lock.js.map +1 -0
  35. package/dist/memory.d.ts +47 -0
  36. package/dist/memory.d.ts.map +1 -0
  37. package/dist/memory.js +118 -0
  38. package/dist/memory.js.map +1 -0
  39. package/dist/options.d.ts +61 -0
  40. package/dist/options.d.ts.map +1 -0
  41. package/dist/options.js +152 -0
  42. package/dist/options.js.map +1 -0
  43. package/dist/pagination/index.d.ts +36 -0
  44. package/dist/pagination/index.d.ts.map +1 -0
  45. package/dist/pagination/index.js +96 -0
  46. package/dist/pagination/index.js.map +1 -0
  47. package/dist/types.d.ts +232 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +2 -0
  50. package/dist/types.js.map +1 -0
  51. package/dist/wrappers.d.ts +16 -0
  52. package/dist/wrappers.d.ts.map +1 -0
  53. package/dist/wrappers.js +20 -0
  54. package/dist/wrappers.js.map +1 -0
  55. package/package.json +85 -4
  56. package/src/cache.ts +611 -0
  57. package/src/client.ts +99 -0
  58. package/src/codec.ts +64 -0
  59. package/src/errors.ts +51 -0
  60. package/src/events.ts +74 -0
  61. package/src/index.ts +28 -0
  62. package/src/keys.ts +19 -0
  63. package/src/lock.ts +164 -0
  64. package/src/memory.ts +154 -0
  65. package/src/options.ts +249 -0
  66. package/src/pagination/index.ts +185 -0
  67. package/src/types.ts +248 -0
  68. package/src/wrappers.ts +25 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cboar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Temporary Holding Version
1
+ # swr-redis
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Stale-while-revalidate caching in Redis for Node.js, with typed caches, distributed fetch locking, and an optional in-memory LRU cache.
4
+
5
+ By default, callers get cached values while one process refreshes stale entries. On a miss, one process fetches and concurrent callers wait instead of flooding your database.
6
+
7
+ [Documentation](https://cboar.github.io/swr-redis/) · [npm package](https://www.npmjs.com/package/swr-redis) · [GitHub](https://github.com/cboar/swr-redis)
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install swr-redis ioredis bson@7
13
+ ```
14
+
15
+ If your application uses MongoDB driver 6, install `bson@6` in that command so the default codec can serialize the driver's `ObjectId` values.
16
+
17
+ ## Define a client and cache
18
+
19
+ In this example, `db` is your application’s data access layer.
20
+
21
+ ```ts
22
+ import { Redis } from 'ioredis'
23
+ import { createSwrClient } from 'swr-redis'
24
+
25
+ interface User {
26
+ id: string
27
+ name: string
28
+ }
29
+
30
+ const redis = new Redis(process.env.REDIS_URL!)
31
+
32
+ const swr = createSwrClient({
33
+ redis,
34
+ prefix: 'my-app:prod',
35
+ ttl: 120,
36
+ staleMultiplier: 5,
37
+ })
38
+
39
+ const userCache = swr.cache({
40
+ name: 'users',
41
+ key: (userId: string) => `user:${userId}`,
42
+ fetch: (userId, { signal }): Promise<User | null> => db.getUser(userId, { signal }),
43
+ })
44
+ ```
45
+
46
+ `prefix` namespaces Redis keys. Entries stay fresh for `ttl` seconds and can be served stale until `ttl * staleMultiplier` seconds after the write.
47
+
48
+ ## Read and update cached values
49
+
50
+ TypeScript infers the argument to `get()` from `key` and the return type from `fetch`.
51
+
52
+ ```ts
53
+ const user = await userCache.get('u_123') // User | null
54
+ ```
55
+
56
+ Update the source of truth first, then update the cached value.
57
+
58
+ ```ts
59
+ const updatedUser = await db.updateUser('u_123', { name: 'Ada' })
60
+ await userCache.set('u_123', updatedUser)
61
+ ```
62
+
63
+ To let the next read fetch the updated value, call `userCache.invalidate('u_123')` after updating the source. To invalidate several entries, pass their logical keys from `cache.key()` to `swr.invalidateKeys()`.
64
+
65
+ ## Choose how stale entries are refreshed
66
+
67
+ Set `mode` on the client or per cache.
68
+
69
+ - `'swr'` (default) serves the stale value while one caller refreshes it in the background.
70
+ - `'swr-serverless'` makes one caller wait for its refresh while other callers get the stale value.
71
+ - `'wait-on-stale'` lets concurrent callers wait for the refresh and fall back to the stale value when their wait times out.
72
+
73
+ For background refreshes in serverless runtimes, pass `waitUntil`. On shutdown, call `await swr.flush()` before closing Redis. [Background refresh lifecycle](https://cboar.github.io/swr-redis/consistency/#background-refresh-lifecycle)
74
+
75
+ ## Choose what happens when Redis fails
76
+
77
+ When Redis fails before a fetch, `'availability'` (default) serves stale data when available or fetches directly from the source without caching. Set `failureStrategy: 'protect-source'` to reject the request and limit load on the source. [Failure strategies](https://cboar.github.io/swr-redis/consistency/#failure-strategies)
78
+
79
+ ## Before you deploy
80
+
81
+ - Include every input that changes the result in the cache key, such as tenant, permission scope, or locale.
82
+ - Version your keys when the cached shape or codec changes.
83
+ - If you enable memory caching, each client has a local copy. Invalidations in another process can leave that copy readable until it expires. [Memory configuration](https://cboar.github.io/swr-redis/configuration/#cache-values-in-memory)
84
+
85
+ ## Compatibility
86
+
87
+ The package is ESM-only, ships TypeScript declarations, and requires Node.js 24+, `ioredis ^5.11.1 || ^6.0.0`, and `bson ^6.10.4 || ^7.0.0`. Standalone Redis and Redis Sentinel are supported. Redis Cluster is unsupported. Your application owns the Redis connection.
88
+
89
+ ## Documentation
90
+
91
+ - [Getting started](https://cboar.github.io/swr-redis/) — reads, updates, key design, source-first writes, and deployment caveats.
92
+ - [Configuration](https://cboar.github.io/swr-redis/configuration/) — option defaults and scopes, dynamic TTLs, in-memory LRU caching, codecs, compression, and timeouts.
93
+ - [Fetch results](https://cboar.github.io/swr-redis/fetch-results/) — fetch metadata, skipping cache writes with `SwrNoCache`, and multi-key writes with `SwrWriteBatch`.
94
+ - [Pagination](https://cboar.github.io/swr-redis/pagination/) — offset-paginated caches with optional page prefetching via `swr-redis/pagination`.
95
+ - [Consistency & failures](https://cboar.github.io/swr-redis/consistency/) — revalidation modes, `waitUntil` / `flush`, failure strategies, and write ordering.
96
+ - [Observability & errors](https://cboar.github.io/swr-redis/observability/) — `onEvent` telemetry, typed error classes, and fatal error handling.
@@ -0,0 +1,35 @@
1
+ import type { ClientInternals } from './client.ts';
2
+ import type { SwrCache, SwrCacheOptions, SwrGetOptions } from './types.ts';
3
+ export declare class SwrCacheImpl<T = unknown, Context = void> implements SwrCache<T, Context> {
4
+ private readonly client;
5
+ private readonly options;
6
+ private readonly fetch;
7
+ private readonly emit?;
8
+ constructor(client: ClientInternals, options: SwrCacheOptions<T, Context>);
9
+ key(context: Context): string;
10
+ get(context: Context, options?: SwrGetOptions): Promise<T>;
11
+ set(context: Context, value: T): Promise<void>;
12
+ invalidate(context: Context): Promise<void>;
13
+ private guardedRead;
14
+ private decodeAndPopulate;
15
+ private tryLock;
16
+ private onStaleHit;
17
+ private onColdMiss;
18
+ private poll;
19
+ private waitForEntry;
20
+ private pollSnapshot;
21
+ private emitPoll;
22
+ private onRedisError;
23
+ private reportRedisError;
24
+ private onFetchError;
25
+ private fetchDirect;
26
+ private refresh;
27
+ private fetchLocked;
28
+ private prepareFetch;
29
+ private commit;
30
+ private safeRelease;
31
+ private prepareWrite;
32
+ private resolvePrimaryTtl;
33
+ }
34
+ export declare function pollDelayMs(pollIntervalMs: number, waitTimeoutMs: number, elapsedMs: number): number;
35
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAmBlD,OAAO,KAAK,EAEV,QAAQ,EACR,eAAe,EAIf,aAAa,EACd,MAAM,YAA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import { decodeEnvelopeValue, encodeEnvelope, readEnvelopeHeader, } from "./codec.js";
2
+ import { isFatalError, SwrTimeoutError, SwrValidationError } from "./errors.js";
3
+ import { bindCacheEmitter, errorEvent, reportRedisError } from "./events.js";
4
+ import { requireNonEmpty } from "./keys.js";
5
+ import { RedisLock } from "./lock.js";
6
+ import { POLL_JITTER, requireTtl, resolveCacheOptions, toRedisTtlSeconds, } from "./options.js";
7
+ import { SwrNoCache, SwrWriteBatch } from "./wrappers.js";
8
+ export class SwrCacheImpl {
9
+ client;
10
+ options;
11
+ fetch;
12
+ emit;
13
+ constructor(client, options) {
14
+ this.client = client;
15
+ this.options = resolveCacheOptions(client.options, options);
16
+ this.fetch = options.fetch;
17
+ this.emit = bindCacheEmitter(client.emit, options.name);
18
+ }
19
+ key(context) {
20
+ return this.options.keyOf(context);
21
+ }
22
+ async get(context, options) {
23
+ options?.signal?.throwIfAborted();
24
+ const key = this.options.keyOf(context);
25
+ const useMemory = this.options.memoryEnabled && options?.memory !== false;
26
+ if (useMemory) {
27
+ const hit = this.client.memory.get(key, Date.now());
28
+ if (hit) {
29
+ this.emit?.({
30
+ type: 'hit',
31
+ key,
32
+ source: 'memory',
33
+ stale: false,
34
+ startedRevalidation: false,
35
+ });
36
+ return hit.value;
37
+ }
38
+ }
39
+ const { keys, redis } = this.client;
40
+ const req = {
41
+ context,
42
+ key,
43
+ dataKey: keys.data(key),
44
+ lockKey: keys.lock(key),
45
+ signal: options?.signal,
46
+ waitUntil: options?.waitUntil,
47
+ useMemory,
48
+ };
49
+ const read = await this.guardedRead(req, async (guard) => {
50
+ let buf;
51
+ try {
52
+ buf = await redis.getBuffer(req.dataKey);
53
+ }
54
+ catch (err) {
55
+ req.signal?.throwIfAborted();
56
+ return { redisError: err };
57
+ }
58
+ req.signal?.throwIfAborted();
59
+ return { entry: this.decodeAndPopulate(buf, 'usable', guard) };
60
+ });
61
+ if ('redisError' in read)
62
+ return await this.onRedisError(req, read.redisError);
63
+ const { entry } = read;
64
+ if (!entry)
65
+ return await this.onColdMiss(req);
66
+ if (!entry.fresh)
67
+ return await this.onStaleHit(req, { value: entry.envelope.value });
68
+ this.emit?.({ type: 'hit', key, source: 'redis', stale: false, startedRevalidation: false });
69
+ return entry.envelope.value;
70
+ }
71
+ async set(context, value) {
72
+ const { redis, keys, memory } = this.client;
73
+ const key = this.options.keyOf(context);
74
+ const ttl = this.resolvePrimaryTtl(context, key, value);
75
+ const { envelope, buffer, ttlSeconds } = this.prepareWrite(value, Date.now(), ttl, this.options.codec, this.options.memoryEnabled);
76
+ const pending = memory.beginWrite([{ key, envelope }]);
77
+ try {
78
+ await redis.swrSetAndClearLock(keys.data(key), keys.lock(key), buffer, ttlSeconds);
79
+ }
80
+ catch (err) {
81
+ memory.settle(pending, 'evict');
82
+ this.reportRedisError(key, err);
83
+ return;
84
+ }
85
+ memory.settle(pending, 'populate');
86
+ }
87
+ async invalidate(context) {
88
+ await this.client.invalidate([this.options.keyOf(context)], this.options.failureStrategy, this.emit);
89
+ }
90
+ async guardedRead(req, read) {
91
+ const { memory } = this.client;
92
+ const guard = req.useMemory ? memory.beginRead(req.key) : undefined;
93
+ try {
94
+ return await read(guard);
95
+ }
96
+ finally {
97
+ memory.endRead(guard);
98
+ }
99
+ }
100
+ decodeAndPopulate(buf, accept, guard) {
101
+ const entry = decodeEntry(buf, accept, this.options.codec);
102
+ if (entry?.fresh)
103
+ this.client.memory.populate(guard, entry.envelope, entry.now);
104
+ return entry;
105
+ }
106
+ async tryLock(req) {
107
+ const { signal } = req;
108
+ signal?.throwIfAborted();
109
+ const lock = new RedisLock(this.client.redis, req.lockKey);
110
+ let acquired;
111
+ try {
112
+ acquired = await lock.acquire(this.options.lockTtlMs);
113
+ }
114
+ catch (err) {
115
+ // Redis may have granted the lock before the reply was lost.
116
+ const release = this.safeRelease(req, lock);
117
+ if (signal?.aborted) {
118
+ await release;
119
+ throw signal.reason;
120
+ }
121
+ return { status: 'redis_error', err };
122
+ }
123
+ if (signal?.aborted) {
124
+ if (acquired)
125
+ await this.safeRelease(req, lock);
126
+ throw signal.reason;
127
+ }
128
+ return acquired ? { status: 'acquired', lock } : { status: 'busy' };
129
+ }
130
+ async onStaleHit(req, stale) {
131
+ const { mode, failureStrategy } = this.options;
132
+ const { key } = req;
133
+ const attempt = await this.tryLock(req);
134
+ if (attempt.status === 'redis_error') {
135
+ // Under protect-source the Redis error is thrown and the stale value is never served.
136
+ if (failureStrategy !== 'protect-source') {
137
+ this.emit?.({ type: 'hit', key, source: 'redis', stale: true, startedRevalidation: false });
138
+ }
139
+ return await this.onRedisError(req, attempt.err, stale);
140
+ }
141
+ const acquired = attempt.status === 'acquired';
142
+ this.emit?.({ type: 'hit', key, source: 'redis', stale: true, startedRevalidation: acquired });
143
+ if (!acquired) {
144
+ return mode === 'wait-on-stale' ? await this.poll(req, stale) : stale.value;
145
+ }
146
+ if (mode === 'swr') {
147
+ // The background refresh must outlive the caller's request and its abort signal.
148
+ const background = { ...req, signal: undefined };
149
+ const refresh = this.refresh(background, attempt.lock, 'stale_revalidation', stale);
150
+ this.client.track(refresh, req.waitUntil);
151
+ return stale.value;
152
+ }
153
+ return await this.refresh(req, attempt.lock, 'stale_revalidation', stale);
154
+ }
155
+ async onColdMiss(req) {
156
+ const attempt = await this.tryLock(req);
157
+ if (attempt.status === 'redis_error')
158
+ return await this.onRedisError(req, attempt.err);
159
+ if (attempt.status === 'busy') {
160
+ this.emit?.({ type: 'miss', key: req.key, action: 'wait' });
161
+ return await this.poll(req);
162
+ }
163
+ this.emit?.({ type: 'miss', key: req.key, action: 'fetch' });
164
+ return await this.refresh(req, attempt.lock, 'cold_miss');
165
+ }
166
+ async poll(req, stale) {
167
+ const progress = { attempts: 0, startedAt: Date.now() };
168
+ let result;
169
+ try {
170
+ result = await this.waitForEntry(req, stale, progress);
171
+ }
172
+ catch (err) {
173
+ this.emitPoll(req, req.signal?.aborted ? 'cancelled' : 'error', progress);
174
+ throw err;
175
+ }
176
+ this.emitPoll(req, result.outcome, progress, result.outcome === 'timeout' ? result.elapsedMs : undefined);
177
+ switch (result.outcome) {
178
+ case 'resolved':
179
+ case 'stale_fallback':
180
+ return result.value;
181
+ case 'timeout': {
182
+ if (stale)
183
+ return stale.value;
184
+ if (this.options.failureStrategy !== 'protect-source')
185
+ return await this.fetchDirect(req);
186
+ const durationMs = result.elapsedMs;
187
+ const err = new SwrTimeoutError(req.key, durationMs);
188
+ this.emit?.(errorEvent('timeout', req.key, { err, durationMs }));
189
+ throw err;
190
+ }
191
+ case 'error':
192
+ return await this.onRedisError(req, result.err, stale);
193
+ case 'lock_stolen':
194
+ return await this.refresh(req, result.lock, 'lock_stolen');
195
+ }
196
+ }
197
+ async waitForEntry(req, stale, progress) {
198
+ const { waitTimeoutMs, pollIntervalMs } = this.options;
199
+ const accept = stale ? 'fresh' : 'usable';
200
+ const { signal } = req;
201
+ while (true) {
202
+ signal?.throwIfAborted();
203
+ const elapsedMs = Date.now() - progress.startedAt;
204
+ if (elapsedMs >= waitTimeoutMs)
205
+ return { outcome: 'timeout', elapsedMs };
206
+ await sleep(pollDelayMs(pollIntervalMs, waitTimeoutMs, elapsedMs), signal);
207
+ signal?.throwIfAborted();
208
+ progress.attempts++;
209
+ const snapshot = await this.pollSnapshot(req, accept);
210
+ if (snapshot.status === 'redis_error')
211
+ return { outcome: 'error', err: snapshot.err };
212
+ if (snapshot.status === 'hit')
213
+ return { outcome: 'resolved', value: snapshot.value };
214
+ if (snapshot.status === 'locked')
215
+ continue;
216
+ if (stale)
217
+ return { outcome: 'stale_fallback', value: stale.value };
218
+ const attempt = await this.tryLock(req);
219
+ if (attempt.status === 'redis_error')
220
+ return { outcome: 'error', err: attempt.err };
221
+ if (attempt.status === 'acquired')
222
+ return { outcome: 'lock_stolen', lock: attempt.lock };
223
+ }
224
+ }
225
+ pollSnapshot(req, accept) {
226
+ return this.guardedRead(req, async (guard) => {
227
+ let data;
228
+ let lock;
229
+ try {
230
+ ;
231
+ [data, lock] = await this.client.redis.mgetBuffer(req.dataKey, req.lockKey);
232
+ }
233
+ catch (err) {
234
+ req.signal?.throwIfAborted();
235
+ return { status: 'redis_error', err };
236
+ }
237
+ req.signal?.throwIfAborted();
238
+ const entry = this.decodeAndPopulate(data ?? null, accept, guard);
239
+ if (entry)
240
+ return { status: 'hit', value: entry.envelope.value };
241
+ return { status: lock ? 'locked' : 'unlocked' };
242
+ });
243
+ }
244
+ emitPoll(req, outcome, progress, durationMs) {
245
+ this.emit?.({
246
+ type: 'poll',
247
+ outcome,
248
+ key: req.key,
249
+ attempts: progress.attempts,
250
+ durationMs: durationMs ?? Date.now() - progress.startedAt,
251
+ });
252
+ }
253
+ async onRedisError(req, err, stale) {
254
+ this.reportRedisError(req.key, err);
255
+ return stale ? stale.value : await this.fetchDirect(req);
256
+ }
257
+ reportRedisError(key, err) {
258
+ reportRedisError([key], err, this.options.failureStrategy, this.emit);
259
+ }
260
+ // Returns the stale fallback when allowed; otherwise rethrows.
261
+ onFetchError(req, err, stale) {
262
+ if (req.signal?.aborted)
263
+ throw err;
264
+ if (!stale) {
265
+ this.emit?.(errorEvent('fetch_cold_failure', req.key, { err }));
266
+ throw err;
267
+ }
268
+ if (isFatalError(err, this.options.isFatal)) {
269
+ this.emit?.(errorEvent('fatal', req.key, { err }));
270
+ if (this.options.mode !== 'swr')
271
+ throw err;
272
+ }
273
+ else {
274
+ this.emit?.(errorEvent('fetch_stale_fallback', req.key, { err }));
275
+ }
276
+ return stale.value;
277
+ }
278
+ async fetchDirect(req) {
279
+ try {
280
+ const result = await this.fetch(req.context, {
281
+ key: this.options.keyOf,
282
+ ...(req.signal !== undefined ? { signal: req.signal } : {}),
283
+ cacheWrite: 'skip',
284
+ });
285
+ if (result instanceof SwrWriteBatch) {
286
+ validateBatch(result, req.key);
287
+ return result.primary;
288
+ }
289
+ return result instanceof SwrNoCache ? result.value : result;
290
+ }
291
+ catch (err) {
292
+ return this.onFetchError(req, err);
293
+ }
294
+ }
295
+ async refresh(req, lock, trigger, stale) {
296
+ let prepared;
297
+ try {
298
+ prepared = await this.fetchLocked(req, lock);
299
+ }
300
+ catch (err) {
301
+ return this.onFetchError(req, err, stale);
302
+ }
303
+ return await this.commit(req, lock, prepared, trigger);
304
+ }
305
+ async fetchLocked(req, lock) {
306
+ const startedAt = Date.now();
307
+ const onRenewError = (err) => this.emit?.(errorEvent('lock_renewal_failure', req.key, { err }));
308
+ try {
309
+ const result = await lock.hold(this.options, onRenewError, () => this.fetch(req.context, {
310
+ key: this.options.keyOf,
311
+ ...(req.signal !== undefined ? { signal: req.signal } : {}),
312
+ cacheWrite: 'attempt',
313
+ }));
314
+ const prepared = this.prepareFetch(req, result, startedAt);
315
+ if (prepared.kind === 'no-cache')
316
+ await this.safeRelease(req, lock);
317
+ return prepared;
318
+ }
319
+ catch (err) {
320
+ await this.safeRelease(req, lock);
321
+ throw err;
322
+ }
323
+ }
324
+ prepareFetch(req, result, startedAt) {
325
+ if (result instanceof SwrNoCache)
326
+ return { kind: 'no-cache', value: result.value };
327
+ const isBatch = result instanceof SwrWriteBatch;
328
+ const value = isBatch ? result.primary : result;
329
+ if (isBatch)
330
+ validateBatch(result, req.key);
331
+ const primaryTtl = (isBatch ? result.ttl : undefined) ?? this.resolvePrimaryTtl(req.context, req.key, value);
332
+ const cachedAtMs = Date.now();
333
+ const { useMemory } = req;
334
+ const entries = [
335
+ {
336
+ key: req.key,
337
+ dataKey: req.dataKey,
338
+ ...this.prepareWrite(value, cachedAtMs, primaryTtl, this.options.codec, useMemory),
339
+ },
340
+ ];
341
+ if (isBatch) {
342
+ for (const { key, value: secondaryValue, ttl, codec } of result.secondary) {
343
+ const encoder = codec ?? this.client.options.codec;
344
+ entries.push({
345
+ key,
346
+ dataKey: this.client.keys.data(key),
347
+ ...this.prepareWrite(secondaryValue, cachedAtMs, ttl ?? primaryTtl, encoder, useMemory),
348
+ });
349
+ }
350
+ }
351
+ return { kind: 'write', value, entries, durationMs: Date.now() - startedAt };
352
+ }
353
+ async commit(req, lock, prepared, trigger) {
354
+ if (prepared.kind === 'no-cache')
355
+ return prepared.value;
356
+ const { memory } = this.client;
357
+ const { value, entries, durationMs } = prepared;
358
+ const pending = memory.beginWrite(entries);
359
+ let committed;
360
+ try {
361
+ committed = await lock.commit(entries);
362
+ }
363
+ catch (err) {
364
+ // The commit may still have run in Redis, so evict memory. Return the value even under
365
+ // protect-source because fetch already succeeded.
366
+ memory.settle(pending, 'evict');
367
+ const [primary, ...secondary] = entries;
368
+ const keys = [primary.key, ...secondary.map((entry) => entry.key)];
369
+ this.emit?.(errorEvent('redis_error_fallback', req.key, { keys, err }));
370
+ await this.safeRelease(req, lock);
371
+ return value;
372
+ }
373
+ // Evict even when the lock was lost: if a reply was lost, ioredis resends the command after
374
+ // reconnecting, so the first run may have written every key before this run found no lock.
375
+ memory.settle(pending, committed ? 'populate' : 'evict');
376
+ this.emit?.(committed
377
+ ? { type: 'refresh', trigger, key: req.key, durationMs }
378
+ : errorEvent('lock_lost', req.key, { durationMs }));
379
+ return value;
380
+ }
381
+ async safeRelease(req, lock) {
382
+ try {
383
+ await lock.release();
384
+ }
385
+ catch (err) {
386
+ this.emit?.(errorEvent('lock_release_failure', req.key, { err }));
387
+ }
388
+ }
389
+ prepareWrite(value, cachedAtMs, ttl, encoder, useMemory) {
390
+ const { staleMultiplier, compression } = this.options;
391
+ const ttlSeconds = toRedisTtlSeconds(ttl, staleMultiplier);
392
+ const envelope = {
393
+ value,
394
+ cachedAtMs,
395
+ freshUntilMs: cachedAtMs + ttl * 1000,
396
+ expiresAtMs: cachedAtMs + ttl * staleMultiplier * 1000,
397
+ };
398
+ const buffer = encodeEnvelope(envelope, encoder, compression);
399
+ if (!useMemory)
400
+ return { buffer, ttlSeconds };
401
+ if (!this.client.memory.clones)
402
+ return { buffer, ttlSeconds, envelope };
403
+ // Clone before writing to Redis so uncloneable values fail before any Redis write.
404
+ return { buffer, ttlSeconds, envelope: { ...envelope, value: structuredClone(value) } };
405
+ }
406
+ resolvePrimaryTtl(context, key, value) {
407
+ const { ttl } = this.options;
408
+ if (typeof ttl === 'number')
409
+ return ttl;
410
+ return requireTtl(ttl({ context, key, value }), 'ttl callback result');
411
+ }
412
+ }
413
+ function decodeEntry(buf, accept, codec) {
414
+ if (!buf)
415
+ return undefined;
416
+ const header = readEnvelopeHeader(buf);
417
+ const deadlineMs = accept === 'fresh' ? header.freshUntilMs : header.expiresAtMs;
418
+ if (Date.now() >= deadlineMs)
419
+ return undefined;
420
+ const value = decodeEnvelopeValue(buf, header, codec);
421
+ // A slow decode can cross the deadline.
422
+ const now = Date.now();
423
+ if (now >= deadlineMs)
424
+ return undefined;
425
+ const { cachedAtMs, freshUntilMs, expiresAtMs } = header;
426
+ return {
427
+ fresh: now < freshUntilMs,
428
+ envelope: { value, cachedAtMs, freshUntilMs, expiresAtMs },
429
+ now,
430
+ };
431
+ }
432
+ function validateBatch(batch, primaryKey) {
433
+ if (batch.ttl !== undefined)
434
+ requireTtl(batch.ttl, 'batch ttl');
435
+ const seenKeys = new Set([primaryKey]);
436
+ for (const { key, ttl } of batch.secondary) {
437
+ requireNonEmpty(key, 'key');
438
+ if (seenKeys.has(key))
439
+ throw new SwrValidationError(`Duplicate cache write key: "${key}"`);
440
+ seenKeys.add(key);
441
+ if (ttl !== undefined)
442
+ requireTtl(ttl, 'secondary ttl');
443
+ }
444
+ }
445
+ function sleep(ms, signal) {
446
+ if (signal?.aborted)
447
+ return Promise.reject(signal.reason);
448
+ return new Promise((resolve, reject) => {
449
+ const onAbort = () => {
450
+ clearTimeout(timer);
451
+ reject(signal.reason);
452
+ };
453
+ const timer = setTimeout(() => {
454
+ signal?.removeEventListener('abort', onAbort);
455
+ resolve();
456
+ }, ms);
457
+ signal?.addEventListener('abort', onAbort, { once: true });
458
+ });
459
+ }
460
+ export function pollDelayMs(pollIntervalMs, waitTimeoutMs, elapsedMs) {
461
+ const jitter = Math.floor(Math.random() * (Math.floor(pollIntervalMs * POLL_JITTER) + 1));
462
+ return Math.min(pollIntervalMs + jitter, Math.max(1, waitTimeoutMs - elapsedMs));
463
+ }
464
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GAEnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAC/E,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAa,MAAM,aAAa,CAAA;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAwB,MAAM,WAAW,CAAA;AAE3D,OAAO,EACL,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,iBAAiB,GAElB,MAAM,cAAc,CAAA;AAUrB,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAoDzD,MAAM,OAAO,YAAY;IACN,MAAM,CAAiB;IACvB,OAAO,CAAkC;IACzC,KAAK,CAAsC;IAC3C,IAAI,CAAO;IAE5B,YAAY,MAAuB,EAAE,OAAoC;QACvE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,mBAAmB,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC3D,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACzD,CAAC;IAED,GAAG,CAAC,OAAgB;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,OAAgB,EAAE,OAAuB;QACjD,OAAO,EAAE,MAAM,EAAE,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