@0xdoublesharp/lru-cache-clustered 0.0.0 → 2.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,375 @@
1
+ # 2.1.0 / 2026-05-03
2
+
3
+ ## Features
4
+
5
+ - **Local L1 cache** -- new `localL1` option adds a per-worker LRU cache in front of the primary-owned shared cache. Off by default. Requires `experimental: true` in v2.1 as an explicit opt-in acknowledgement of the eventual-consistency model.
6
+
7
+ ```ts
8
+ new LRUCacheClustered({
9
+ namespace: 'users',
10
+ max: 50_000,
11
+ ttl: 60_000,
12
+ localL1: { enabled: true, experimental: true, ttl: 2_000 },
13
+ });
14
+ ```
15
+
16
+ - **Per-call bypass options** -- `get`, `has`, `peek`, `mGet`, `fetch`, and `memoize` accept `{ bypassL1: true }` to skip the local cache on a single call. `set` accepts `{ updateL1: true }` to populate the caller's L1 after a successful write; bulk writes clear the local L1.
17
+
18
+ - **Method-level L1 controls** -- `localL1.methods` can restrict L1 to specific read families (`get`, `has`, and `fetch`). When `methods` is provided, omitted method keys are disabled. `memoize()` delegates to `fetch()`, so its L1 behavior follows the `fetch` setting.
19
+
20
+ - **Invalidation mode control** -- the default `localL1.invalidation: 'broadcast'` subscribes same-process and cross-worker invalidation pushes. `localL1.invalidation: 'ttl-only'` is available for callers that intentionally want to rely only on the local TTL window.
21
+
22
+ - **New methods**:
23
+ - `clearLocal()` -- flush this worker's L1 for the namespace without touching the primary.
24
+ - `invalidateLocal(key)` -- drop a single key from this worker's L1.
25
+ - `localStats()` -- returns `{ enabled, hits, misses, sets, invalidations, evictions, staleHits, size, ipcAvoided }`.
26
+ - `withoutLocal()` -- returns a bypass view that routes all reads through the primary; the original instance is unaffected.
27
+
28
+ - **New events**: `l1:hit`, `l1:miss`, `l1:set`, `l1:invalidate`, `l1:evict`, and `l1:stale-hit`. Each carries `{ namespace, key }`; namespace-wide invalidations use `key: '*'`.
29
+
30
+ - **Wire format** -- IPC responses now carry an optional `version` field; push (invalidation broadcast) messages were added. Backward compatible: a v2.0 worker talking to a v2.1 primary ignores the unknown field; a v2.1 worker talking to a v2.0 primary simply receives no invalidation broadcasts and relies on TTL expiry.
31
+
32
+ ## Fixes and validation
33
+
34
+ - Fixed `fetch(..., { bypassL1: true })` so followers do not observe or repopulate stale L1 state while preserving primary-side single-flight coordination.
35
+ - Tightened L1 method-option semantics so provided `methods` objects consistently disable omitted read families.
36
+ - Hardened local invalidation handling for nullish or unencodable keys, repeated unsubscribe calls, worker destroy, bulk operations, TTL changes, capacity changes, and primary load/purge paths.
37
+ - Added regression coverage for L1 TTL clamping, per-entry TTL handling, local stats/events, same-process invalidation, worker invalidation broadcasts, and fetch bypass behavior.
38
+ - Test coverage now reaches 100% statements, branches, functions, and lines for `src/**/*.ts`.
39
+
40
+ # 2.0.0 / 2026-04-28
41
+
42
+ ## Breaking changes — TypeScript rewrite
43
+
44
+ - Rewritten in TypeScript with full IPC type safety via discriminated unions
45
+ - Adopted `lru-cache@11` native API (was a translated layer over `lru-cache@6`)
46
+ - Renamed methods: `del → delete`, `reset → clear`, `prune → purgeStale`, `length`/`itemCount → size`, `stale → allowStale`
47
+ - Renamed options: `maxAge → ttl`, `stale → allowStale`
48
+ - Removed `parse` / `stringify` options and `setObject` / `getObject` / `mGetObjects` / `mSetObjects` — callers handle serialization
49
+ - Removed `prune: <crontime>` option — schedule `purgeStale()` from your own scheduler
50
+ - Removed `execute(method, ...args)` — call methods directly
51
+ - Renamed `master` to `primary` everywhere (matches `cluster.isPrimary`)
52
+ - Internal IPC method renamed `sendToMaster` → `sendToPrimary`
53
+
54
+ ## Features and infrastructure
55
+
56
+ - Canonical package name is now `@0xdoublesharp/lru-cache-clustered`; `lru-cache-for-clusters-as-promised` is published from the same build at the same version
57
+ - Renamed canonical class to `LRUCacheClustered`; `LRUCacheForClustersAsPromised` is retained as a backward-compatible alias (both are exported)
58
+ - Repository moved to `github.com/doublesharp/lru-cache-clustered`
59
+ - Publish workflow (`scripts/prepare-publish.mjs` + `.github/workflows/npm-publish.yml`) builds once, prepares scoped and legacy package directories, and publishes both at the same version with npm provenance via GitHub Actions OIDC, triggered by `v*` tags
60
+ - Publish prep validates required build artifacts before creating package directories
61
+ - Scoped and legacy package copies share primary state in one process to avoid duplicate IPC listeners during migration
62
+ - Dual ESM + CJS publish via `package.json` `exports`
63
+ - Generic types: `LRUCacheClustered<K, V>`
64
+ - Node `>=22` required
65
+ - Added `destroy()` to tear down namespace caches, stats, and fetch coordination state on the primary
66
+ - Added explicit startup controls via `LRUCacheClustered.bootstrap()` and `cache.healthCheck()`
67
+ - Added size-bounded cache support (`maxSize`, `maxEntrySize`, and `size` on write paths)
68
+ - `fetch()` now uses primary-side single-flight coordination across workers; `memoize()` is exported as a top-level helper that delegates to it
69
+ - Added `wrap()` for transparent encode/decode of cached values (gzip, MessagePack, custom symmetric codecs)
70
+ - Structured error transport over IPC: rejected promises carry `name`, `message`, `code`, `stack`, and the `cause` chain
71
+ - Dropped runtime deps: `cron`, `uuid` — request IDs use a per-process monotonic counter
72
+ - pnpm for development; node:test + c8 for tests/coverage; tsup + tsc for build
73
+ - husky `pre-commit` and `pre-push` hooks; lint-staged on staged files
74
+ - 100% line/statement/function coverage
75
+ - Property-based fuzz tests for cache, IPC, and worker layers
76
+ - CI: Node 24 test workflow, Node 22 coverage workflow for Codecov, Doublcov HTML artifacts, and GitHub Pages coverage publishing from `main`, plus a Quality workflow running lint, typecheck, knip, type-coverage, build, and size-limit
77
+ - New `assets/`: logo (`LRUCacheClustered.png`) and topology SVG diagram
78
+ - New `examples/`: six runnable clustered server examples (users / memoize, rate-limit / incr, sessions, idempotency / setIfAbsent, compressed documents / wrap, multilayer LRU + Redis)
79
+ - `incr` / `decr` retained (race-safe across workers)
80
+ - `failsafe` and `timeout` retained for worker IPC
81
+
82
+ ## Migration
83
+
84
+ See README "Migrating from older releases" for the full mapping.
85
+
86
+ # 1.7.1 / 2021-03-25
87
+
88
+ - Added `static getInstance(options)` to asynchronously return an `LRUCacheClustered` once the underlying `LRUCache` is guaranteed to exist.
89
+ - Added `static getAllCaches()` to return all underlying `LRUCache` instances keyed by namespace. _Use only when `cluster.isMaster === true`._
90
+ - Added `getCache()` to return underlying `LRUCache` instance. _Use only when `cluster.isMaster === true`._
91
+ - Added test coverage via GitHub Actions
92
+ - Bug fixes for namespaces
93
+ - Bug fixes for prune cron jobs
94
+ - Refactoring for maintainability
95
+ - Updated tests
96
+ - Updated dependencies
97
+
98
+ # 1.7.0 / 2021-03-25
99
+
100
+ - Refactoring for maintainability
101
+ - Update dependencies
102
+ - More reliable test coverage
103
+
104
+ # 1.6.1 / 2021-03-20
105
+
106
+ - Update types
107
+
108
+ # 1.6.0 / 2021-03-20
109
+
110
+ - Refactor codebase to be more maintainable
111
+ - Support for external `parse` and `stringify` functions, used for object caching, more efficient on large objects
112
+ - Update tests, 100% code coverage
113
+ - Update documentation
114
+ - Update dependencies
115
+ - npm audit fix
116
+
117
+ # 1.5.25 / 2021-03-02
118
+
119
+ - Update dependencies
120
+
121
+ # 1.5.24 / 2020-07-02
122
+
123
+ - Update dependencies
124
+ - npm audit fix
125
+
126
+ # 1.5.23 / 2020-06-10
127
+
128
+ - Typescript support (thanks @hanspeter1!)
129
+ - Update dependencies
130
+
131
+ # 1.5.22 / 2020-05-01
132
+
133
+ - Remove yarn.lock
134
+
135
+ # 1.5.21 / 2020-05-01
136
+
137
+ - Update dependencies
138
+
139
+ # 1.5.20 / 2019-09-29
140
+
141
+ - Update dependencies
142
+
143
+ # 1.5.19 / 2019-08-03
144
+
145
+ - Update dependencies
146
+ - Fix coverage badges with nyc
147
+
148
+ # 1.5.18 / 2019-08-01
149
+
150
+ - Update dependencies
151
+ - Use nyc for coverage
152
+
153
+ # 1.5.17 / 2019-04-25
154
+
155
+ - Update dependencies
156
+ - Lint code
157
+
158
+ # 1.5.16 / 2017-11-21
159
+
160
+ - Update dependencies
161
+
162
+ # 1.5.15 / 2017-10-14
163
+
164
+ - Update dependencies
165
+
166
+ # 1.5.14 / 2017-09-11
167
+
168
+ - Update dependencies
169
+
170
+ # 1.5.13 / 2017-08-04
171
+
172
+ - Update dependencies
173
+
174
+ # 1.5.12 / 2017-07-06
175
+
176
+ - Update dependencies
177
+
178
+ # 1.5.11 / 2017-05-07
179
+
180
+ - Update dependencies
181
+
182
+ # 1.5.10 / 2017-05-07
183
+
184
+ - Deduplicate common methods - fixes CodeClimate rating to 4.0
185
+
186
+ # 1.5.9 / 2017-05-06
187
+
188
+ - Remove `npm-shrinkwrap.json`
189
+ - Update dependencies
190
+
191
+ # 1.5.8 / 2017-03-03
192
+
193
+ - Use Google ESLint config
194
+ - Update dependencies
195
+
196
+ # 1.5.7 / 2017-02-02
197
+
198
+ - Use `yarn` for installs
199
+ - Update dependencies and dev dependencies
200
+
201
+ # 1.5.6 / 2016-12-14
202
+
203
+ - Update dependencies
204
+
205
+ # 1.5.5 / 2016-12-14
206
+
207
+ - Update dependencies
208
+
209
+ # 1.5.4 / 2016-12-05
210
+
211
+ - Update dependencies
212
+
213
+ # 1.5.3 / 2016-11-19
214
+
215
+ - Update `uuid` and `developer-tools`
216
+
217
+ # 1.5.2 / 2016-11-17
218
+
219
+ - Improved debug logging
220
+
221
+ # 1.5.1 / 2016-11-17
222
+
223
+ - Add support for `mSetObjects()` and `mGetObjects()`
224
+ - Pass namespace through to pruning job for debugging
225
+
226
+ # 1.5.0 / 2016-11-16
227
+
228
+ - Add support for `mGet([key])`, `mSet({key: value}, maxAge)`, and `mDel([key])`.
229
+
230
+ # 1.4.6 / 2016-11-16
231
+
232
+ - Always use a shared cache for consistent behavior
233
+
234
+ # 1.4.5 / 2016-11-15
235
+
236
+ - Bug fix for null objects
237
+
238
+ # 1.4.4 / 2016-11-15
239
+
240
+ - Support for getting and setting objects + test coverage
241
+ Update deps
242
+ Bump version
243
+
244
+ # 1.4.3 / 2016-11-12
245
+
246
+ - Update ESLint settings
247
+ Remove duplicated code
248
+ Update deps
249
+ Bump version
250
+
251
+ # 1.4.2 / 2016-11-08
252
+
253
+ - Update dependencies
254
+ Bump version
255
+
256
+ # 1.4.1 / 2016-10-26
257
+
258
+ - bump version
259
+ - fix the tests, provide more coverage
260
+ fix for case when no options are passed in.
261
+ - Give longer to create cache
262
+ Overwrite settings if they are different (allow workers to just use
263
+ name, for example).
264
+ Better properties on create return options
265
+ Bugfix, cache master caches by namespace.
266
+
267
+ # 1.4.0 / 2016-10-21
268
+
269
+ - Use cron to optionally prune cache on the master
270
+ Support for `maxAge` parameter on `set()`
271
+ Updated debugging
272
+ Updated test coverage
273
+ Updated deps
274
+ Bumped version
275
+ - use web sequence diagrams
276
+
277
+ # 1.3.1 / 2016-10-11
278
+
279
+ - bump version
280
+ - Update code climate config
281
+ - dedupe keys test
282
+ - dedupe tests
283
+ - Dedupe test code
284
+ - fix hello test
285
+ - Refactor tests to improve coverage and remove duplicated code.
286
+ - Downgrade version of `eslint-plugin-import`
287
+ - Update deps
288
+ Add pre-push testing
289
+ Allow code climate to calc duplication
290
+
291
+ # 1.3.0 / 2016-10-03
292
+
293
+ - When `cluster.isMaster===true` and the `caches[namespace]` is
294
+ populated, use that instead of creating a `new LRUCache()` - the master
295
+ thread will now act on the same cache as the workers.
296
+ Support for updating the max, maxAge, stale of the cache.
297
+ Update README for new features.
298
+ Update tests to provide 100% coverage.
299
+ Bump version
300
+ - use a long random string as the lru key value to give the promise time
301
+ to call the failsafe with reject()
302
+ - update eslint config for code climate
303
+ - disable duplication check
304
+ - Fix `import/no-extraneous-dependencies` value
305
+
306
+ # 1.2.0 / 2016-09-30
307
+
308
+ - Bump version
309
+ - Add support and tests for `incr()`/`decr()`
310
+ Update readme.
311
+ Syntax cleanup.
312
+
313
+ # 1.1.0 / 2016-09-29
314
+
315
+ - bump version
316
+ - Update to failsafe with `resolve(undefined)` and `reject(Error)` via
317
+ `options.failsafe=reject`, update docs
318
+
319
+ # 1.0.6 / 2016-09-29
320
+
321
+ - Update readme, bump version
322
+ - bump version
323
+
324
+ # 1.0.5 / 2016-09-29
325
+
326
+ - Export `init` method stub
327
+ Some refactoring
328
+ Add tests for timeout coverage - 100% covered!
329
+ Update README for `init()`
330
+
331
+ # 1.0.4 / 2016-09-26
332
+
333
+ - Update dependencies, new lint rules, start worker for each cpu core and
334
+ then call mocha done(), don’t resolve a value if the callback has timed
335
+ out, set timeout in options, update README, bump version
336
+
337
+ # 1.0.3 / 2016-09-21
338
+
339
+ - Bump version, remove code climate issue count since it won’t update
340
+ - Update standards/linting
341
+ Update main filename
342
+ Update tests
343
+ - update developer-tools confs
344
+ lint code
345
+ - update code climate config
346
+ - use .eslintrc instead of .eslintrc.js
347
+ - ignore eslintrc.js in code climate, update config file to standards
348
+ - check in code climate file
349
+
350
+ # 1.0.2 / 2016-08-25
351
+
352
+ - fix link in readme, bump version
353
+
354
+ # 1.0.1 / 2016-08-25
355
+
356
+ - add header, eslint config, clean up code, bump version to 1.0.1
357
+
358
+ # 1.0.0 / 2016-08-25
359
+
360
+ - fix typo, more example updates
361
+ - fix example
362
+ - more comments
363
+ - add more comments
364
+ - Update README.md
365
+ update with info about `namespace` option.
366
+ - Update README.md
367
+ update with api and options, fix example
368
+ - Update README.md
369
+ add description, install, usage, patterns.
370
+ - fix for properties on promisified lru-cache
371
+ - Update readme and add git repo to package
372
+ - Update to create coverage badge
373
+ - Only fork twice for tests
374
+ - First version, linted with test coverage.
375
+ - Initial commit
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Justin Silver
3
+ Copyright (c) 2016-2026 Justin Silver
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal