tricache 1.0.1 → 2.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 (127) hide show
  1. package/README.md +89 -93
  2. package/dashboards/tricache-alerts.yaml +80 -4
  3. package/dashboards/tricache-grafana.json +54 -1
  4. package/dashboards/tricache-inventory.rules.yml +21 -0
  5. package/dist/cache-service-BV5T8-20.d.cts +1064 -0
  6. package/dist/cache-service-UZXOQGEY.js +14 -0
  7. package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
  8. package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
  9. package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
  10. package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
  11. package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
  12. package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
  13. package/dist/chunk-RBJRTGFK.js +94 -0
  14. package/dist/chunk-S5N65I45.js +17 -0
  15. package/dist/cli.cjs +3694 -1070
  16. package/dist/cli.d.cts +12 -0
  17. package/dist/cli.js +210 -14
  18. package/dist/dashboard/index.cjs +111 -29
  19. package/dist/dashboard/index.d.cts +185 -0
  20. package/dist/dashboard/index.d.ts +5 -3
  21. package/dist/dashboard/index.js +1 -1
  22. package/dist/drizzle/index.cjs +3578 -1068
  23. package/dist/drizzle/index.d.cts +46 -0
  24. package/dist/drizzle/index.d.ts +2 -2
  25. package/dist/drizzle/index.js +6 -2
  26. package/dist/edge/index.cjs +368 -162
  27. package/dist/edge/index.d.cts +134 -0
  28. package/dist/edge/index.d.ts +11 -4
  29. package/dist/edge/index.js +314 -155
  30. package/dist/hono/index.cjs +3614 -1087
  31. package/dist/hono/index.d.cts +93 -0
  32. package/dist/hono/index.d.ts +7 -5
  33. package/dist/hono/index.js +16 -9
  34. package/dist/hono-CMv2VdQ6.d.cts +404 -0
  35. package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
  36. package/dist/http/index.cjs +3712 -1124
  37. package/dist/http/index.d.cts +103 -0
  38. package/dist/http/index.d.ts +13 -5
  39. package/dist/http/index.js +92 -43
  40. package/dist/index.cjs +4067 -1252
  41. package/dist/index.d.cts +1071 -0
  42. package/dist/index.d.ts +123 -27
  43. package/dist/index.js +878 -21
  44. package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
  45. package/dist/murmur3-DF8BFRnu.d.ts +99 -0
  46. package/dist/nestjs/index.cjs +3635 -1112
  47. package/dist/nestjs/index.d.cts +299 -0
  48. package/dist/nestjs/index.d.ts +120 -33
  49. package/dist/nestjs/index.js +132 -43
  50. package/dist/next/index.cjs +3704 -1175
  51. package/dist/next/index.d.cts +238 -0
  52. package/dist/next/index.d.ts +39 -11
  53. package/dist/next/index.js +202 -102
  54. package/dist/prisma/index.cjs +29 -18
  55. package/dist/prisma/index.d.cts +62 -0
  56. package/dist/prisma/index.d.ts +2 -2
  57. package/dist/prisma/index.js +17 -18
  58. package/dist/serialize-worker.cjs +162 -39
  59. package/dist/serialize-worker.d.cts +2 -0
  60. package/dist/serialize-worker.js +9 -7
  61. package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
  62. package/dist/types-F8vRWMrE.d.ts +1636 -0
  63. package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
  64. package/dist/utils-Bvzn-rKS.d.ts +29 -0
  65. package/package.json +116 -37
  66. package/src/adapters/auto-pipeliner.ts +150 -26
  67. package/src/adapters/node-redis.ts +106 -27
  68. package/src/cache-service.ts +2215 -793
  69. package/src/cli.ts +25 -14
  70. package/src/codec.ts +3 -3
  71. package/src/compression.ts +39 -16
  72. package/src/cross-region.ts +22 -4
  73. package/src/dashboard/handler.ts +26 -6
  74. package/src/dashboard/html.ts +35 -10
  75. package/src/dashboard/index.ts +35 -13
  76. package/src/dashboard/types.ts +3 -1
  77. package/src/disk-tier.ts +448 -102
  78. package/src/drizzle/index.ts +2 -1
  79. package/src/edge/adapters/cloudflare-do.ts +25 -10
  80. package/src/edge/adapters/cloudflare-kv.ts +12 -9
  81. package/src/edge/adapters/upstash.ts +27 -11
  82. package/src/edge/cache.ts +200 -110
  83. package/src/edge/hono.ts +23 -6
  84. package/src/edge/types.ts +17 -5
  85. package/src/encryption.ts +50 -18
  86. package/src/env.d.ts +1 -1
  87. package/src/errors.ts +12 -0
  88. package/src/hono/index.ts +19 -9
  89. package/src/http/express.ts +62 -17
  90. package/src/http/fastify.ts +35 -21
  91. package/src/http/utils.ts +60 -20
  92. package/src/index.ts +6 -0
  93. package/src/ipc-telemetry.ts +35 -9
  94. package/src/latency-watchdog.ts +5 -1
  95. package/src/nestjs/decorators.ts +11 -6
  96. package/src/nestjs/index.ts +2 -0
  97. package/src/nestjs/keyv-adapter.ts +68 -0
  98. package/src/nestjs/tricache.module.ts +15 -12
  99. package/src/nestjs/tricache.store.ts +69 -26
  100. package/src/nestjs/types.ts +30 -16
  101. package/src/next/cache-handler.ts +151 -53
  102. package/src/next/index.ts +1 -0
  103. package/src/next/types.ts +25 -0
  104. package/src/origin-capacity.ts +134 -0
  105. package/src/prisma/index.ts +17 -24
  106. package/src/remote-snapshot.ts +37 -27
  107. package/src/serialize-worker.ts +8 -5
  108. package/src/sigv4-snapshot-adapter.ts +37 -27
  109. package/src/smart-memory-cache.ts +121 -44
  110. package/src/types.ts +117 -37
  111. package/src/utils/cgroup.ts +12 -0
  112. package/src/utils/config-comparison.ts +29 -0
  113. package/src/utils/deadline.ts +14 -0
  114. package/src/utils/diagnostics.ts +27 -0
  115. package/src/utils/lz4-size.ts +74 -0
  116. package/src/utils/namespace-key.ts +48 -0
  117. package/src/utils/query-key.ts +13 -0
  118. package/src/utils/redis-slot.ts +13 -0
  119. package/src/utils/snapshot-transfer.ts +83 -0
  120. package/src/utils/work-limits.ts +73 -0
  121. package/src/utils/write-revision.ts +4 -0
  122. package/src/wasm/bloom-filter-wasm.ts +25 -5
  123. package/src/worker-pool.ts +44 -15
  124. package/src/wtiny-lfu.ts +82 -20
  125. package/dist/cache-service-MG7PN6MX.js +0 -12
  126. package/dist/chunk-3I5L7K6I.js +0 -704
  127. package/dist/chunk-BQRURGGD.js +0 -60
@@ -0,0 +1,14 @@
1
+ import {
2
+ CacheService,
3
+ INDEFINITE_TTL_SECONDS,
4
+ ProcessTerminationBus,
5
+ deepMergeOptions
6
+ } from "./chunk-MB3DMVWN.js";
7
+ import "./chunk-EJXG7WO6.js";
8
+ import "./chunk-KV7KISK2.js";
9
+ export {
10
+ CacheService,
11
+ INDEFINITE_TTL_SECONDS,
12
+ ProcessTerminationBus,
13
+ deepMergeOptions
14
+ };
@@ -1,4 +1,4 @@
1
- import { C as CacheOptions, b as CacheMetrics, c as CacheHealthStatus, d as CachePresetType, e as CrossRegionInvalidationEvent, f as CachePriority, W as WrapOptions, a as InvalidateTagOptions, g as CachePingResult, D as DiskBackpressureStats, L as LockOptions, E as EncryptionMode, h as WTinyLfuStats } from './types-Dyip5wAl.js';
1
+ import { C as CacheOptions, b as CacheMetrics, c as CacheHealthStatus, d as CachePresetType, e as CrossRegionInvalidationEvent, f as CachePriority, W as WrapOptions, a as InvalidateTagOptions, g as CachePingResult, D as DiskBackpressureStats, L as LockOptions, E as EncryptionMode, h as WTinyLfuStats } from './types-F8vRWMrE.js';
2
2
 
3
3
  /**
4
4
  * TierLatencyWatchdog — Graduated, self-healing tier latency watchdog.
@@ -141,6 +141,8 @@ declare class IpcTelemetryServer {
141
141
  private server;
142
142
  readonly socketPath: string;
143
143
  private _closed;
144
+ private _starting;
145
+ private readonly sockets;
144
146
  private _exitHandler;
145
147
  private _sigintHandler;
146
148
  private _sigtermHandler;
@@ -149,6 +151,7 @@ declare class IpcTelemetryServer {
149
151
  * Start listening on the IPC socket / pipe.
150
152
  */
151
153
  start(): Promise<void>;
154
+ private startInternal;
152
155
  /**
153
156
  * Build a complete telemetry snapshot from the underlying cache provider.
154
157
  */
@@ -215,6 +218,14 @@ declare class ProcessTerminationBus {
215
218
  }
216
219
  declare function deepMergeOptions(base: CacheOptions, overrides?: Partial<CacheOptions>): CacheOptions;
217
220
  declare class CacheService {
221
+ private readonly _originWork;
222
+ private readonly _backgroundWork;
223
+ private readonly _originCapacityLimiter;
224
+ private readonly _dependencyBudget;
225
+ private readonly _dependencyReleases;
226
+ private readonly _dependencyExpirations;
227
+ private readonly _lifecycle;
228
+ private readonly _singletonConfig;
218
229
  private readonly logger;
219
230
  private readonly enc;
220
231
  private readonly codec;
@@ -227,6 +238,11 @@ declare class CacheService {
227
238
  private readonly opts;
228
239
  /** Pre-computed once — opts.namespace never changes after construction. */
229
240
  private readonly _namespace;
241
+ private readonly _namespacePrefix;
242
+ private readonly _dataPrefix;
243
+ private readonly _tagSetPrefix;
244
+ private readonly _tagVersionPrefix;
245
+ private readonly _lockPrefix;
230
246
  private readonly prefixLen;
231
247
  /** Pre-computed once — disableRedis and redisHost never change after construction. */
232
248
  private readonly _redisDisabled;
@@ -241,6 +257,9 @@ declare class CacheService {
241
257
  private readonly keyTags;
242
258
  /** tag → { version, lastSyncedAt } for generational tag invalidation (bounded to 10,000 entries) */
243
259
  private readonly tagVersions;
260
+ /** Share active generation reads only; retain at most the tag-cache ceiling. */
261
+ private readonly _tagVersionRefreshes;
262
+ private _tagRefreshEpoch;
244
263
  /**
245
264
  * Dependency index: source glob pattern → Set of namespaced dependent keys.
246
265
  * When an exact-key delete matches a registered pattern, all dependents are cascaded.
@@ -248,6 +267,8 @@ declare class CacheService {
248
267
  private readonly dependencyIndex;
249
268
  /** Reverse index of namespaced dependent key → source glob patterns */
250
269
  private readonly keyDependencies;
270
+ /** Active writers retain their dependency edges even before admission or after eviction. */
271
+ private readonly _pendingDependencies;
251
272
  private readonly _cgroupMemoryLimit;
252
273
  private redis;
253
274
  private redisConnecting;
@@ -271,9 +292,34 @@ declare class CacheService {
271
292
  private subClient;
272
293
  private streamClient;
273
294
  private _lastStreamId;
295
+ private _restoredSnapshot;
296
+ private _backplaneAvailable;
297
+ private _backplaneUnavailableReason;
298
+ private _backplaneUnavailableSince;
299
+ private _backplaneStateSince;
300
+ private _lastBackplaneHeartbeatAt;
301
+ private _backplaneHeartbeatInterval;
302
+ private _backplaneHeartbeat;
303
+ private _heartbeatPublishInFlight;
304
+ private _backplaneSubscriptionReady;
305
+ private _backplaneTransportEpoch;
306
+ private _retryBackplaneSubscription;
307
+ private _preparedBackplaneClient;
308
+ private _invalidationReadEpoch;
309
+ private _otelCleanup;
310
+ private _streamRecovering;
311
+ private readonly _backplaneDisposers;
274
312
  private _destroyed;
275
313
  private readonly _pendingDiskDeletes;
314
+ /** Active invalidations fence cold Redis reads until their asynchronous deletion settles. */
315
+ private readonly _pendingRedisInvalidations;
276
316
  private _globalEpoch;
317
+ private _pendingSpillCount;
318
+ private readonly _pendingSpills;
319
+ /** Strict reads trust only revisions spilled in this consumer epoch; bounded independently of disk size. */
320
+ private readonly _protectedSpillRevisions;
321
+ private _suppressSpills;
322
+ private _diskCleanupScheduled;
277
323
  private readonly _keyMutationEpochs;
278
324
  /**
279
325
  * Pattern tombstones for disk tier.
@@ -282,15 +328,33 @@ declare class CacheService {
282
328
  * pattern tombstones in memory to intercept subsequent disk reads and evict matching files.
283
329
  */
284
330
  private readonly _patternTombstones;
331
+ private _diskInvalidatedBefore;
285
332
  private _addPatternTombstone;
286
333
  private _isTombstonedByPattern;
287
334
  private _assertActive;
335
+ private _beginRedisInvalidation;
336
+ private _isRedisReadInvalidated;
288
337
  private _bumpKeyMutation;
289
338
  private _getKeyMutationEpoch;
339
+ /** Capture a commit fence before asynchronous computation outside the cache. */
340
+ captureMutationFence(cacheKey: string): () => boolean;
341
+ /** Force tag re-sync without forgetting locally observed monotonic generations. */
342
+ refreshTagVersions(): void;
343
+ private _fenceInvalidation;
344
+ private _invalidateDiskKey;
345
+ private _scheduleDiskCleanup;
346
+ private _reserveDependencies;
347
+ private _registerDependencies;
348
+ private _trackPendingDependencies;
349
+ private _rememberTags;
350
+ private _restoreEntryMetadata;
290
351
  private _removeKeyTags;
291
352
  private _removeKeyDependencies;
353
+ private _clearDependencyMetadata;
354
+ private _notifyReadObserver;
355
+ private _runOrigin;
292
356
  private _handleL1Eviction;
293
- private _removePrefixFromIndices;
357
+ private _removePatternFromIndices;
294
358
  private _sweepExpiredMetadata;
295
359
  private _runOomCheck;
296
360
  private _ipcServer?;
@@ -337,12 +401,11 @@ declare class CacheService {
337
401
  * meaningful configuration divergence worth flagging (security/correctness
338
402
  * relevant — not cosmetic, e.g. log level).
339
403
  */
340
- private static readonly DIVERGENT_KEYS;
341
404
  /** Returns the names of options that differ between `a` and the live `b`. */
342
405
  private static optionsDiff;
343
406
  /** Increment the singleton-divergence counter (surfaced in `metrics()`). */
344
407
  bumpSingletonDivergence(): void;
345
- /** Read-only view of the options the singleton was constructed with. */
408
+ /** Sanitized diagnostic view; retain the original options/adapters to reuse configuration. */
346
409
  get options(): CacheOptions;
347
410
  /**
348
411
  * Async factory — accepts a Promise that resolves to CacheOptions.
@@ -357,15 +420,25 @@ declare class CacheService {
357
420
  /** Derive the globalThis key for a given set of options. */
358
421
  private static globalKey;
359
422
  /**
360
- * Prepend the configured namespace to a raw cache key.
361
- * Returns the key unchanged when namespace is empty.
423
+ * Encode the namespace, data domain, and raw key as an unambiguous v3 key.
362
424
  *
363
- * This is the only place the namespace prefix is applied — callers always
364
- * receive and provide un-prefixed keys in the public API.
425
+ * Callers always receive and provide logical keys in the public API.
365
426
  */
366
427
  private nk;
367
- /** Strip the instance namespace prefix from a namespaced key (inverse of `nk`). */
368
- private unnk;
428
+ private tagIndexKey;
429
+ private tagIndexPrefix;
430
+ private tagVersionKey;
431
+ private tagVersionPrefix;
432
+ private lockKey;
433
+ private undk;
434
+ /**
435
+ * Validate a snapshot write timestamp before age/skew arithmetic.
436
+ *
437
+ * NaN and non-numeric values previously made every comparison false, so a
438
+ * malformed timestamp skipped both the future-skew and maximum-age gates.
439
+ * Missing or invalid values are rejected outright rather than treated as 0.
440
+ */
441
+ private _snapshotWrittenAt;
369
442
  /** Apply TTL jitter: multiply ttlMs by (1 ± jitterFactor). */
370
443
  private _jitterTtl;
371
444
  /** Shared no-op span for the common case where no tracer is configured.
@@ -374,7 +447,23 @@ declare class CacheService {
374
447
  /** Start an OTEL-compatible span if a tracer is configured. Returns a no-op span otherwise. */
375
448
  private _startSpan;
376
449
  private createDedicatedRedisClient;
450
+ private _listenBackplane;
451
+ private _strictInvalidationReadProtectionEnabled;
452
+ private _setBackplaneUnavailable;
453
+ private _flushLocalCacheAfterInvalidationRecovery;
454
+ private _setBackplaneAvailable;
455
+ private _rejectCachedRead;
456
+ private _ensureCachedReadAllowed;
457
+ /** Shared admission/commit/response fence. Health checks must also evaluate elapsed deadlines. */
458
+ private _cachedReadAllowed;
459
+ private _checkBackplaneDeadline;
460
+ private _startBackplaneHeartbeat;
461
+ private _publishBackplaneHeartbeat;
462
+ private _acceptBackplaneHeartbeat;
463
+ private _protectedConsumerDisconnected;
464
+ private _initProtectedPubSub;
377
465
  private initBackplane;
466
+ private _resetAfterStreamGap;
378
467
  private _startStreamConsumer;
379
468
  /**
380
469
  * Validate + apply one XREAD stream entry. `fields` is the flat ioredis
@@ -384,8 +473,17 @@ declare class CacheService {
384
473
  * number. Invalid entries are logged and dropped — never applied.
385
474
  */
386
475
  /** @internal Exposed for testing. */
387
- _processStreamEntry(fields: string[]): void;
476
+ _processStreamEntry(fields: string[], deferHeartbeat?: (src: unknown, nonce: unknown) => void): void;
388
477
  private _applyInvalidationEvent;
478
+ /**
479
+ * Parse an optional tag version from either transport.
480
+ *
481
+ * Pub/Sub previously forwarded any numeric value (including `1.5`) while
482
+ * Streams rejected non-integers, so the two transports disagreed on the same
483
+ * logical payload. Both now share this validation: absent means "no version",
484
+ * and anything present must be a non-negative safe integer.
485
+ */
486
+ private _parseTagVersion;
389
487
  /** @internal Exposed for testing. Applies a raw backplane JSON message to local state. */
390
488
  _handleBackplaneMessage(message: string): void;
391
489
  private publishInvalidation;
@@ -403,14 +501,21 @@ declare class CacheService {
403
501
  private _setLocalTagVersion;
404
502
  private _isGenerationalEntryStale;
405
503
  private _deleteRedisKeys;
406
- private _parseGenerationalRedisHash;
504
+ private _parseRedisHash;
407
505
  private _readRedisEntry;
408
506
  private _getTagVersion;
507
+ private _refreshTagVersion;
508
+ private _readRedisBatch;
509
+ private _promoteRedisEntry;
510
+ private _readDiskEntry;
511
+ /** Common write policy and metadata across get/set/revalidation/draining. */
512
+ private _writeRedisEntry;
409
513
  private _deleteIfStale;
410
514
  /**
411
515
  * Serialize payload for L2 Redis storage applying compression and encryption as configured.
412
516
  * Offloads to worker thread if pool is active and payload exceeds threshold.
413
517
  */
518
+ private _redisContext;
414
519
  private _serializeAndEncrypt;
415
520
  /**
416
521
  * Deserialize raw L2 Redis entry applying decryption and decompression as needed.
@@ -429,8 +534,12 @@ declare class CacheService {
429
534
  * NOTE: fs.writeFileSync is INTENTIONAL here: this method is invoked during SIGTERM/SIGINT
430
535
  * process termination hooks where asynchronous I/O would risk the Node.js event loop dying or
431
536
  * process.exit() being called before the snapshot is physically written to disk.
537
+ *
538
+ * @returns `true` when a snapshot was written (or when there was nothing to write),
539
+ * `false` when the write failed. Callers that report shutdown success must
540
+ * check this value.
432
541
  */
433
- writeSnapshot(altPath?: string): void;
542
+ writeSnapshot(altPath?: string): boolean;
434
543
  /**
435
544
  * Loads cold-start snapshot from disk into L1 memory.
436
545
  * NOTE: fs.readFileSync is INTENTIONAL here: this method is invoked synchronously inside the
@@ -469,7 +578,7 @@ declare class CacheService {
469
578
  * @param opts.notFoundTtl - Override TTL in seconds for `null`/`undefined` fetch results.
470
579
  * Caches negative lookups to avoid repeated DB hits for missing keys.
471
580
  */
472
- get<T>(cacheKey: string, fetchFn: () => Promise<T>, ttlSeconds?: number, opts?: {
581
+ get<T>(cacheKey: string, fetchFn: (signal?: AbortSignal) => Promise<T>, ttlSeconds?: number, opts?: {
473
582
  priority?: CachePriority;
474
583
  swr?: number;
475
584
  refreshAhead?: number;
@@ -482,6 +591,8 @@ declare class CacheService {
482
591
  * On an L1/L2 hit the tags are already registered — this field is a no-op for hits.
483
592
  */
484
593
  tags?: string[];
594
+ /** Dependency patterns registered when a miss populates the entry. */
595
+ dependsOn?: string[];
485
596
  }): Promise<T>;
486
597
  /**
487
598
  * Graceful shutdown flusher for Kubernetes preStop hooks, NestJS onApplicationShutdown,
@@ -493,6 +604,7 @@ declare class CacheService {
493
604
  * @param timeoutMs Maximum time permitted for snapshot persistence before timing out. Default: 8000ms.
494
605
  */
495
606
  flushSnapshotOnShutdown(timeoutMs?: number): Promise<boolean>;
607
+ private _drainPendingDiskWork;
496
608
  /**
497
609
  * Internal graceful shutdown trigger invoked by ProcessTerminationBus.
498
610
  */
@@ -514,16 +626,19 @@ declare class CacheService {
514
626
  * tags: ['users'],
515
627
  * });
516
628
  */
517
- wrap<T>(cacheKey: string, fetchFn: () => Promise<T>, options?: WrapOptions): Promise<T>;
629
+ wrap<T>(cacheKey: string, fetchFn: (signal?: AbortSignal) => Promise<T>, options?: WrapOptions): Promise<T>;
518
630
  private _revalidate;
519
631
  /** Explicitly write a value into L1 (+ L2 in production). */
520
632
  set<T>(cacheKey: string, data: T, ttlSeconds?: number, priority?: CachePriority, opts?: {
521
633
  tags?: string[];
522
634
  dependsOn?: string[];
523
635
  }): Promise<void>;
636
+ private _set;
524
637
  /**
525
- * Register tags for a cache key in the in-process index and (if Redis is enabled) in
526
- * the Redis SADD index. Tags are best-effort — a Redis failure does not throw.
638
+ * Retain remote discovery through the entry's hard deadline plus cleanup grace.
639
+ * Each atomic registration initializes new sets and only extends expiring sets;
640
+ * existing persistent sets retain their unknown member lifetimes. Local metadata
641
+ * is maintained at admission/retention changes. Redis failure remains best effort.
527
642
  */
528
643
  private _registerTags;
529
644
  /**
@@ -537,8 +652,12 @@ declare class CacheService {
537
652
  /**
538
653
  * Distributed counter.
539
654
  *
540
- * When Redis is active, atomically increments the key via `INCR` and returns
541
- * the new (fleet-wide) value. On a Redis error it increments `counters.errors`
655
+ * When Redis is active, one single-key script increments and applies missing
656
+ * expiry, returning the new fleet-wide value. A positive TTL starts a fixed
657
+ * window only when no expiry exists; subsequent increments do not extend it.
658
+ * Omitted/zero TTL creates a permanent counter and preserves existing expiry.
659
+ * Positive fractional seconds round up to milliseconds. Invalid TTLs reject
660
+ * before mutation. On a Redis error it increments `counters.errors`
542
661
  * and, by default, fails OPEN — returning `0` so a caller's
543
662
  * `if (count > LIMIT) reject()` guard does NOT reject during an outage. Set
544
663
  * `failClosed: true` to re-throw the error instead, enforcing the limit even
@@ -621,7 +740,7 @@ declare class CacheService {
621
740
  */
622
741
  scan<T = unknown>(fn: (rawKey: string, value: T, offset: number) => void): void;
623
742
  /**
624
- * Extend the TTL of a key in L1 (and fire-and-forget EXPIRE in Redis) without fetching.
743
+ * Extend the TTL of a key in L1 and Redis without fetching.
625
744
  * Returns `false` if the key is absent or already expired.
626
745
  *
627
746
  * @param newTtlSeconds - The new TTL from now, in seconds.
@@ -635,12 +754,14 @@ declare class CacheService {
635
754
  * const fresh = cache.getIfFresh('user:123');
636
755
  * if (fresh !== null) return fresh; // serve from L1, no network hop
637
756
  */
757
+ private _isLocallyInvalidated;
638
758
  getIfFresh<T = unknown>(cacheKey: string): T | null;
759
+ private _prepareWriteValue;
639
760
  private _prepareReadValue;
640
761
  /**
641
- * Pure read across cache tiers (L1 RAM → L1.5 Disk → L2 Redis) without invoking a fetcher.
762
+ * Origin-free read across L1, optional disk, and Redis without invoking a fetcher.
642
763
  * Returns the cached value if found and valid, or `null` if absent / expired.
643
- * Does not write dummy entries on misses or trigger side-effects.
764
+ * Promotes hits and updates metrics/access policy; it can perform stale cleanup.
644
765
  *
645
766
  * @example
646
767
  * const val = await cache.peek<User>('user:123');
@@ -655,7 +776,7 @@ declare class CacheService {
655
776
  * @param ttl - TTL in seconds for newly fetched values. Accepts a per-key function
656
777
  * `(key) => number` so heterogeneous TTLs can be batched in one call.
657
778
  */
658
- mget<T>(keys: string[], fetchFn?: (missKeys: string[]) => Promise<Record<string, T> | Map<string, T>>, ttl?: number | ((key: string) => number), priority?: CachePriority): Promise<(T | undefined)[]>;
779
+ mget<T>(keys: string[], fetchFn?: (missKeys: string[], signal?: AbortSignal) => Promise<Record<string, T> | Map<string, T>>, ttl?: number | ((key: string) => number), priority?: CachePriority): Promise<(T | undefined)[]>;
659
780
  /**
660
781
  * Returns a Promise that resolves once the cache is fully initialised and any
661
782
  * startup warming configured via `warmKeys` has completed.
@@ -815,6 +936,7 @@ declare class CacheService {
815
936
  bloom: {
816
937
  checks: number;
817
938
  falsePositives: number;
939
+ absentChecks: number;
818
940
  };
819
941
  compression: {
820
942
  compressed: number;
@@ -890,9 +1012,20 @@ declare class CacheService {
890
1012
  /**
891
1013
  * When an exact key `deletedKey` is removed, cascade to every dependent key
892
1014
  * that was registered via `dependsOn` and whose source pattern matches.
893
- * Transitive dependencies are traversed with cycle protection via a visited Set.
1015
+ * Collect the complete closure before mutating indices, including current pending
1016
+ * writers. Fence all affected work synchronously; callers release Redis read
1017
+ * fences only after remote deletion has settled.
894
1018
  */
895
1019
  private _cascadeDependencies;
1020
+ private _cascadeDependenciesForPattern;
1021
+ private _cascadeDependencyClosure;
1022
+ /** Whether two `*`-only globs can match at least one common string. */
1023
+ private _globPatternsIntersect;
1024
+ private _publishPatternAndKeyInvalidations;
1025
+ /** Attempt every publication even when an awaited transport rejects one key. */
1026
+ private _publishKeyInvalidations;
1027
+ /** A peer's 'del' can accompany a set: remove dependent Redis values, never the source. */
1028
+ private _completeBackplaneCascade;
896
1029
  /** Return a full metrics snapshot. */
897
1030
  metrics(): CacheMetrics;
898
1031
  /** Return auto-pipelining metrics, or null if pipelining is disabled. */