@0xdoublesharp/lru-cache-clustered 2.1.2 → 2.1.3

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 (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +42 -75
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 2.1.3 / 2026-11-08
2
+
3
+ - Simplify the README, consolidate runnable examples, and redraw the cache topology with larger labels and a high-resolution PNG embed linked to the SVG.
4
+ - Update README links and npm repository metadata to the canonical `0xdoublesharp/lru-cache-clustered` repository.
5
+ - Update seven development dependencies within their existing major versions while preserving the seven-day release waiting policy.
6
+ - Resolve Zod 4.6.7 and override affected glob and minimatch versions with 14.0.3 and 11.0.3 to address development-tool resource-exhaustion and cancellation advisories.
7
+ - Backport the import plugin's minimatch 11 compatibility fix while its upstream release completes the waiting period.
8
+ - Add a deterministic regression test proving that an asynchronous IPC response failure does not resend the response or apply a counter mutation twice.
9
+ - Authenticate Codecov uploads with GitHub OIDC and scope coverage and Pages permissions to their respective jobs.
10
+
11
+ The runtime API, runtime dependencies, and Node.js 22 minimum are unchanged.
12
+
1
13
  # 2.1.2 / 2026-10-15
2
14
 
3
15
  - Handle asynchronous primary response and invalidation send failures when workers disconnect, without retrying mutations.
package/README.md CHANGED
@@ -1,28 +1,22 @@
1
1
  <p align="center">
2
- <img src="https://raw.githubusercontent.com/doublesharp/lru-cache-clustered/main/assets/LRUCacheClustered.png" alt="A pika, the project mascot" width="180" height="180">
2
+ <img src="https://raw.githubusercontent.com/0xdoublesharp/lru-cache-clustered/main/assets/LRUCacheClustered.png" alt="A pika, the project mascot" width="128" height="128">
3
3
  </p>
4
4
 
5
5
  # @0xdoublesharp/lru-cache-clustered
6
6
 
7
7
  [![npm](https://img.shields.io/npm/v/%400xdoublesharp%2Flru-cache-clustered.svg)](https://www.npmjs.com/package/@0xdoublesharp/lru-cache-clustered)
8
- [![CI](https://github.com/doublesharp/lru-cache-clustered/actions/workflows/ci.yml/badge.svg)](https://github.com/doublesharp/lru-cache-clustered/actions/workflows/ci.yml)
9
- [![Coverage](https://codecov.io/gh/doublesharp/lru-cache-clustered/branch/main/graph/badge.svg)](https://codecov.io/gh/doublesharp/lru-cache-clustered)
8
+ [![CI](https://github.com/0xdoublesharp/lru-cache-clustered/actions/workflows/ci.yml/badge.svg)](https://github.com/0xdoublesharp/lru-cache-clustered/actions/workflows/ci.yml)
9
+ [![Coverage](https://codecov.io/gh/0xdoublesharp/lru-cache-clustered/branch/main/graph/badge.svg)](https://codecov.io/gh/0xdoublesharp/lru-cache-clustered)
10
10
  [![Downloads](https://img.shields.io/npm/dt/%400xdoublesharp%2Flru-cache-clustered.svg)](https://www.npmjs.com/package/@0xdoublesharp/lru-cache-clustered)
11
11
 
12
- Let your Node.js workers share what they have already learned. When one worker caches a database result, the others can reuse it instead of loading and storing their own copies.
12
+ Shared in-memory [LRU caches](https://github.com/isaacs/node-lru-cache) for Node.js cluster workers, with atomic counters, coordinated fetches, and optional worker-local caching.
13
13
 
14
- This package keeps namespaced [LRU caches](https://github.com/isaacs/node-lru-cache) in a Node.js cluster's primary process. LRU means least recently used: when the cache fills up, it removes the entries you have used least recently. Workers access the shared cache through an asynchronous API over inter-process communication, or IPC. Atomic counters and fetch coordination also run in the primary.
14
+ The primary process holds one cache per namespace. Workers share its entries through an asynchronous API over inter-process communication (IPC), so a value loaded by one worker is available to the others. No separate cache service is required; data stays in memory for the lifetime of the primary.
15
15
 
16
- No separate cache service is required. The shared data lives in memory for the lifetime of the primary process. Optional local L1 caches keep hot values inside individual workers to avoid repeated IPC reads.
17
-
18
- <p align="center">
19
- <img src="https://raw.githubusercontent.com/doublesharp/lru-cache-clustered/main/assets/topology.svg" alt="The primary owns shared namespaced caches. Workers read and write through IPC, with optional local caches and invalidation messages." width="100%">
20
- </p>
16
+ [Quick start](#quick-start) · [How it works](#how-it-works) · [Examples](#use-cases) · [Local L1](#local-l1-mode) · [API](#api)
21
17
 
22
18
  ## What you get
23
19
 
24
- Each worker can reuse the same cached data, take a turn loading a missing value, and update shared counters without racing another worker.
25
-
26
20
  | Capability | How it works |
27
21
  | ---------------------- | ------------------------------------------------------------------------------------------------ |
28
22
  | Shared cache storage | One primary-owned cache per namespace, with optional extra copies in worker L1 caches. |
@@ -36,18 +30,18 @@ Each worker can reuse the same cached data, take a turn loading a missing value,
36
30
 
37
31
  ## Install
38
32
 
39
- Install this package and the cache engine it uses. Both JavaScript and TypeScript applications can use it.
40
-
41
33
  ```sh
42
34
  npm install @0xdoublesharp/lru-cache-clustered lru-cache@^11
43
35
  ```
44
36
 
45
37
  For pnpm or Yarn, use `pnpm add` or `yarn add` with the same package names. `lru-cache` is a peer dependency, so your application controls its installed version within the supported range.
46
38
 
47
- Requires Node.js 22 or newer. Includes ESM and CommonJS builds and TypeScript declarations.
39
+ Requires **Node.js 22 or newer**. Includes ESM and CommonJS builds and TypeScript declarations.
48
40
 
49
41
  > `@0xdoublesharp/lru-cache-clustered` is the canonical package name. `lru-cache-for-clusters-as-promised` is published from the same build at the same version.
50
42
 
43
+ **2.1.3** is a maintenance release with clearer documentation and security updates to development tooling. See the [release notes](./CHANGELOG.md#213--2026-11-08) for details.
44
+
51
45
  ## Quick start
52
46
 
53
47
  Start a few workers and give their caches the same name. A write from any worker goes into the shared cache in the primary.
@@ -83,46 +77,46 @@ Both workers read the same entry. `getInstance()` waits for namespace registrati
83
77
 
84
78
  Import the package in the primary before `cluster.fork()`. The import installs the IPC listener; `bootstrap()` makes that setup explicit. Instances that share a namespace must agree on primary cache options such as `max` and `ttl`.
85
79
 
86
- ## Use cases
80
+ ## How it works
81
+
82
+ The primary owns the shared caches. Each namespace identifies one cache, and instances using that namespace must agree on options such as `max`, `ttl`, and `allowStale`. Conflicting options throw during initialization.
87
83
 
88
- Use it when several workers in one Node.js cluster need the same temporary data. The most useful patterns save repeated work or coordinate short-lived state.
84
+ <p align="center">
85
+ <a href="https://raw.githubusercontent.com/0xdoublesharp/lru-cache-clustered/main/assets/topology.svg">
86
+ <img src="https://raw.githubusercontent.com/0xdoublesharp/lru-cache-clustered/main/assets/topology.png" alt="One primary process holds shared namespaced caches. Workers send IPC requests and receive responses. Each worker can optionally keep an L1 cache for local hits; writes reach the primary and trigger asynchronous invalidation." width="800">
87
+ </a>
88
+ </p>
89
89
 
90
- | Idea | Pattern | Example |
91
- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
92
- | Stop a popular profile from triggering duplicate database queries | `memoize()` or `fetch()` lets workers reuse a cached result and coordinate concurrent misses. | [User lookup server](./examples/clustered-users-server.ts) |
93
- | Limit API requests across workers | `incr()` updates one shared counter. Its first write starts the TTL window; later increments keep that deadline. | [Rate limiter](./examples/clustered-rate-limit-server.ts) |
94
- | Share temporary session data | `set()`, `get()`, and `delete()` share entries across workers. Keep durable session state elsewhere. | [Session server](./examples/clustered-session-server.ts) |
95
- | Suppress repeated job submissions | `setIfAbsent()` lets one worker claim a cached key. Expiration, eviction, or restart can allow another claim. | [Idempotent intake](./examples/clustered-idempotency-server.ts) |
96
- | Keep large generated documents in less cache space | `wrap()` compresses stored values and decodes them on reads. | [Compressed documents](./examples/clustered-compressed-documents-server.ts) |
97
- | Reduce repeated Redis reads | Use this shared cache in front of Redis, then add a small worker L1 for hot reads. | [Multilayer cache](./examples/clustered-multilayer-redis-server.ts) |
90
+ - **In the primary**, operations call the namespace's `LRUCache` directly.
91
+ - **In a worker**, operations send typed IPC requests and return promises. With L1 enabled, eligible local hits skip IPC. Writes still reach the primary, which broadcasts invalidations by default.
98
92
 
99
- For example, a report endpoint can use the report parameters as a cache key and `fetch()` to coordinate generation. Include tenant and authorization context when they affect the result.
93
+ > **Initialization.** In a worker, `new LRUCacheClustered(...)` sends an `init` message immediately. `cache.ready` waits for ordering but swallows initialization errors. Use `await LRUCacheClustered.getInstance(...)` or `await cache.healthCheck()` to fail startup when registration fails.
100
94
 
101
- The cache belongs to one primary process. Separate clusters, containers, and machines do not share it. Use a remote cache or database when you need that wider scope, durable state, or coordination that must survive eviction and restarts. Shared counters and claims are atomic while their keys remain present; they do not provide durable quotas or exactly-once job processing.
95
+ ## Use cases
102
96
 
103
- Namespaces separate application data by name. They do not restrict worker access, so all workers must be trusted.
97
+ The [example guide](./examples/README.md) includes request commands, ports, and environment settings. Run these commands from a checkout with dependencies installed.
104
98
 
105
- ## Runnable examples
99
+ | Example | Pattern | Run |
100
+ | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | -------------------------- |
101
+ | [User lookups](./examples/clustered-users-server.ts) | Share database results with `memoize()` and `fetch()`. | `pnpm example:users` |
102
+ | [Rate limiting](./examples/clustered-rate-limit-server.ts) | Use atomic counters with a fixed TTL window. | `pnpm example:rate-limit` |
103
+ | [Sessions](./examples/clustered-session-server.ts) | Share temporary session reads and writes. | `pnpm example:sessions` |
104
+ | [Job intake](./examples/clustered-idempotency-server.ts) | Suppress duplicate submissions with `setIfAbsent()`. | `pnpm example:idempotency` |
105
+ | [Compressed documents](./examples/clustered-compressed-documents-server.ts) | Encode stored values with `wrap()`. | `pnpm example:documents` |
106
+ | [Local L1 controls](./examples/clustered-l1-controls-server.ts) | Try method filters, bypass reads, invalidation, and write-through population. | `pnpm example:l1` |
107
+ | [Redis layers](./examples/clustered-multilayer-redis-server.ts) | Put shared memory and worker L1 in front of Redis. Requires Redis. | `pnpm example:multilayer` |
106
108
 
107
- Start an example server, send it requests, and watch workers share cached results. The [example guide](./examples/README.md) has curl commands, ports, and environment settings.
109
+ The [basic L1 server](./examples/clustered-l1-server.ts) also runs with `node --import tsx examples/clustered-l1-server.ts`.
108
110
 
109
- | Command | What to explore |
110
- | -------------------------- | ------------------------------------------------------------------------------------ |
111
- | `pnpm example:users` | Shared read-through user cache with `memoize()` and `fetch()`. |
112
- | `pnpm example:rate-limit` | Fixed-window counters across workers. |
113
- | `pnpm example:sessions` | Shared session reads and writes. |
114
- | `pnpm example:idempotency` | Temporary job claims with `setIfAbsent()`. |
115
- | `pnpm example:documents` | Compression with `wrap()`. |
116
- | `pnpm example:l1` | Method filtering, bypass reads, local invalidation, and write-through L1 population. |
117
- | `pnpm example:multilayer` | Shared memory caching in front of Redis. Requires Redis. |
111
+ For example, a report endpoint can use the report parameters as a cache key and `fetch()` to coordinate generation. Include tenant and authorization context when they affect the result.
118
112
 
119
- The [basic L1 server](./examples/clustered-l1-server.ts) can also run with `node --import tsx examples/clustered-l1-server.ts`.
113
+ The cache belongs to one primary process. Separate clusters, containers, and machines do not share it. Use a remote cache or database when you need that wider scope, durable state, or coordination that must survive eviction and restarts. Shared counters and claims are atomic while their keys remain present; they do not provide durable quotas or exactly-once job processing.
120
114
 
121
- ## Local L1 mode
115
+ Namespaces separate application data by name. They do not restrict worker access, so all workers must be trusted.
122
116
 
123
- Keep a small copy of frequently read values inside each worker. Repeated reads can stay in that worker instead of asking the primary again.
117
+ ## Local L1 mode
124
118
 
125
- Enable the optional L1 cache with `localL1`. The primary remains the source of truth and owns every write. Invalidation messages tell workers to drop local entries after changes, but delivery is asynchronous.
119
+ Enable `localL1` to keep frequently read values inside each worker and avoid repeated IPC reads. The primary owns every write. Invalidation messages tell workers to drop local entries after changes, but delivery is asynchronous.
126
120
 
127
121
  ```ts
128
122
  type Product = { sku: string; name: string };
@@ -187,19 +181,6 @@ By default, same-process and cross-worker writes broadcast invalidations so hot
187
181
 
188
182
  See [`docs/l1.md`](docs/l1.md) for the full consistency model, stats, events, method options, and failure modes.
189
183
 
190
- ## How it works
191
-
192
- Think of the primary as a shared cupboard and the workers as people borrowing from it. A namespace names one cupboard. Workers with the same namespace share its contents.
193
-
194
- `new LRUCacheClustered(...)` branches at construction:
195
-
196
- - **In the primary** (`cluster.isPrimary === true`), the instance owns and operates on the in-process `LRUCache` for its namespace directly, without IPC.
197
- - **In a worker**, every operation becomes a typed IPC request to the primary; the returned Promise resolves with the response.
198
-
199
- Instances in different workers that share a `namespace` operate on the same primary-side cache. Those instances should agree on cache options (`max`, `ttl`, `allowStale`, ...): reusing a namespace with conflicting options throws rather than silently keeping whichever process initialized it first.
200
-
201
- > **Initialization semantics.** In a worker, `new LRUCacheClustered(...)` eagerly sends the `init` message, but `cache.ready` is ordering-only and intentionally swallows init failure. Use `await cache.healthCheck()` or `await LRUCacheClustered.getInstance(...)` when startup should fail fast if the primary cannot register the namespace.
202
-
203
184
  ## Performance profile
204
185
 
205
186
  Sharing saves duplicate cache storage, but asking another process for a value takes time. A small local cache can speed up repeated reads, at the cost of extra copies and a brief stale-data window.
@@ -266,8 +247,6 @@ The same methods work in the primary and in workers. Await shared-cache operatio
266
247
 
267
248
  ### Static
268
249
 
269
- These helpers set up the shared cache before you start using it.
270
-
271
250
  | Method | Description |
272
251
  | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
273
252
  | `LRUCacheClustered.bootstrap()` | Installs the primary-side cluster listener immediately. Useful when you want an explicit bootstrap call instead of relying on module import side effects. |
@@ -276,8 +255,6 @@ These helpers set up the shared cache before you start using it.
276
255
 
277
256
  ### Core
278
257
 
279
- Store a value, read it back, check whether it exists, or remove it.
280
-
281
258
  | Method | Returns | Notes |
282
259
  | --------------------------------------------- | ------------------------- | -------------------------------------------------------------- |
283
260
  | `get(key, { bypassL1? })` | `Promise<V \| undefined>` | |
@@ -325,8 +302,6 @@ Count events without workers overwriting each other, or load a missing value onc
325
302
 
326
303
  ### Local L1
327
304
 
328
- These controls affect the extra cache inside this process. They help you see whether local reads are saving trips to the primary.
329
-
330
305
  | Method / event | Returns / payload | Notes |
331
306
  | ------------------------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------- |
332
307
  | `localStats()` | `L1Stats \| undefined` | `undefined` when local L1 is disabled. |
@@ -340,8 +315,6 @@ These controls affect the extra cache inside this process. They help you see whe
340
315
 
341
316
  ### Lifecycle, metrics, tunables
342
317
 
343
- Check the cache, inspect its activity, change its limits, or remove its namespace.
344
-
345
318
  | Method | Returns | Notes |
346
319
  | ---------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
347
320
  | `getRemainingTTL(key)` | `Promise<number>` | ms until expiry. `Infinity` for keys with no TTL; `0` for missing keys. |
@@ -386,8 +359,6 @@ await cache.get('user:42'); // decoded back to { id: 42, name: 'ada' }
386
359
 
387
360
  ## `memoize` helper
388
361
 
389
- Give a function a memory. Calling it again with the same cache key can reuse the previous result instead of repeating a database query or API request.
390
-
391
362
  `memoize(cache, fn, keyFn, opts)` calls `cache.fetch()` under the hood. `keyFn` must include every input that can change the result, including tenant or permission context when relevant.
392
363
 
393
364
  ```ts
@@ -435,8 +406,6 @@ A missing key is normal. A failed operation is different: handle its rejected pr
435
406
 
436
407
  ## Debugging
437
408
 
438
- Turn on logs to see whether workers are reaching the primary and which requests they send.
439
-
440
409
  ```sh
441
410
  DEBUG=lru-cache-clustered-* node app.js
442
411
  ```
@@ -449,18 +418,14 @@ Available namespaces:
449
418
 
450
419
  ## Migration
451
420
 
452
- Existing applications can move to the scoped package name while keeping the compatibility alias during the transition.
453
-
454
421
  `LRUCacheClustered` is the canonical class; `LRUCacheForClustersAsPromised` remains an alias. The [migration guide](./docs/migration.md) maps the older methods, options, and package name. The [changelog](./CHANGELOG.md) records release-specific changes.
455
422
 
456
423
  ## Development
457
424
 
458
- Clone the project, install its dependencies, and run the checks before changing code. The examples are small servers you can use to explore the behavior yourself.
459
-
460
425
  For development, use a current Node.js 22 LTS patch release, at least 22.13, or Node.js 24 LTS. Use the pnpm version recorded in `package.json`; the runtime minimum for applications remains Node.js 22.
461
426
 
462
427
  ```sh
463
- git clone https://github.com/doublesharp/lru-cache-clustered.git
428
+ git clone https://github.com/0xdoublesharp/lru-cache-clustered.git
464
429
  cd lru-cache-clustered
465
430
  corepack enable
466
431
  pnpm install --frozen-lockfile
@@ -480,8 +445,10 @@ pnpm check
480
445
 
481
446
  When changing cache behavior, add a regression test that retains the same cache instances and checks the resulting values. For L1 changes, verify warm hits, invalidation, and expiration. Cluster tests use child processes under both JSON and advanced serialization.
482
447
 
483
- Dependency resolution waits seven days after publication through `minimumReleaseAge` in `pnpm-workspace.yaml`. Use frozen lockfile installs for reproducible checks. Release preparation with `pnpm prepare:publish` creates scoped and legacy package directories under `dist-publish/`; the [publishing workflow](./.github/workflows/npm-publish.yml) handles publication.
448
+ Dependency resolution waits seven days after publication through `minimumReleaseAge` in `pnpm-workspace.yaml`. Use frozen lockfile installs for reproducible checks. The [dependency update notes](./docs/dependency-updates.md) describe security overrides and the import-plugin compatibility patch.
449
+
450
+ Release preparation with `pnpm prepare:publish` creates scoped and legacy package directories under `dist-publish/`. Pushing a `vX.Y.Z` tag matching the version in `package.json` triggers the [publishing workflow](./.github/workflows/npm-publish.yml), which runs the package checks and publishes both names to npm with provenance through GitHub OIDC.
484
451
 
485
452
  ## License
486
453
 
487
- You can use, modify, and distribute this package under the MIT license. See [LICENSE](./LICENSE) for the terms.
454
+ [MIT](./LICENSE).
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.1.2",
2
+ "version": "2.1.3",
3
3
  "description": "Shared in-memory LRU caches for Node.js cluster workers, with atomic counters, coordinated fetches, and optional local caching.",
4
4
  "type": "module",
5
5
  "sideEffects": false,
@@ -33,12 +33,12 @@
33
33
  },
34
34
  "repository": {
35
35
  "type": "git",
36
- "url": "git+https://github.com/doublesharp/lru-cache-clustered.git"
36
+ "url": "git+https://github.com/0xdoublesharp/lru-cache-clustered.git"
37
37
  },
38
38
  "bugs": {
39
- "url": "https://github.com/doublesharp/lru-cache-clustered/issues"
39
+ "url": "https://github.com/0xdoublesharp/lru-cache-clustered/issues"
40
40
  },
41
- "homepage": "https://github.com/doublesharp/lru-cache-clustered#readme",
41
+ "homepage": "https://github.com/0xdoublesharp/lru-cache-clustered#readme",
42
42
  "keywords": [
43
43
  "lru",
44
44
  "mru",