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.
- package/README.md +89 -93
- package/dashboards/tricache-alerts.yaml +80 -4
- package/dashboards/tricache-grafana.json +54 -1
- package/dashboards/tricache-inventory.rules.yml +21 -0
- package/dist/cache-service-BV5T8-20.d.cts +1064 -0
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-CREOp7MM.d.ts → cache-service-tpyrXvlH.d.ts} +157 -24
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/{chunk-2AJKEQMZ.js → chunk-KV7KISK2.js} +54 -5
- package/dist/{chunk-JYQFQJNJ.js → chunk-MB3DMVWN.js} +3424 -1022
- package/dist/chunk-RBJRTGFK.js +94 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +3694 -1070
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +210 -14
- package/dist/dashboard/index.cjs +111 -29
- package/dist/dashboard/index.d.cts +185 -0
- package/dist/dashboard/index.d.ts +5 -3
- package/dist/dashboard/index.js +1 -1
- package/dist/drizzle/index.cjs +3578 -1068
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +368 -162
- package/dist/edge/index.d.cts +134 -0
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +314 -155
- package/dist/hono/index.cjs +3614 -1087
- package/dist/hono/index.d.cts +93 -0
- package/dist/hono/index.d.ts +7 -5
- package/dist/hono/index.js +16 -9
- package/dist/hono-CMv2VdQ6.d.cts +404 -0
- package/dist/{hono-DSV2ve66.d.ts → hono-Dvq04kX9.d.ts} +33 -7
- package/dist/http/index.cjs +3712 -1124
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +92 -43
- package/dist/index.cjs +4067 -1252
- package/dist/index.d.cts +1071 -0
- package/dist/index.d.ts +123 -27
- package/dist/index.js +878 -21
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/murmur3-DF8BFRnu.d.ts +99 -0
- package/dist/nestjs/index.cjs +3635 -1112
- package/dist/nestjs/index.d.cts +299 -0
- package/dist/nestjs/index.d.ts +120 -33
- package/dist/nestjs/index.js +132 -43
- package/dist/next/index.cjs +3704 -1175
- package/dist/next/index.d.cts +238 -0
- package/dist/next/index.d.ts +39 -11
- package/dist/next/index.js +202 -102
- package/dist/prisma/index.cjs +29 -18
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +17 -18
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-Dyip5wAl.d.ts → types-F8vRWMrE.d.cts} +186 -54
- package/dist/types-F8vRWMrE.d.ts +1636 -0
- package/dist/{utils-CEsU_Z0s.d.ts → utils-Bvzn-rKS.d.cts} +3 -1
- package/dist/utils-Bvzn-rKS.d.ts +29 -0
- package/package.json +116 -37
- package/src/adapters/auto-pipeliner.ts +150 -26
- package/src/adapters/node-redis.ts +106 -27
- package/src/cache-service.ts +2215 -793
- package/src/cli.ts +25 -14
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +22 -4
- package/src/dashboard/handler.ts +26 -6
- package/src/dashboard/html.ts +35 -10
- package/src/dashboard/index.ts +35 -13
- package/src/dashboard/types.ts +3 -1
- package/src/disk-tier.ts +448 -102
- package/src/drizzle/index.ts +2 -1
- package/src/edge/adapters/cloudflare-do.ts +25 -10
- package/src/edge/adapters/cloudflare-kv.ts +12 -9
- package/src/edge/adapters/upstash.ts +27 -11
- package/src/edge/cache.ts +200 -110
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +17 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +62 -17
- package/src/http/fastify.ts +35 -21
- package/src/http/utils.ts +60 -20
- package/src/index.ts +6 -0
- package/src/ipc-telemetry.ts +35 -9
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +15 -12
- package/src/nestjs/tricache.store.ts +69 -26
- package/src/nestjs/types.ts +30 -16
- package/src/next/cache-handler.ts +151 -53
- package/src/next/index.ts +1 -0
- package/src/next/types.ts +25 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +17 -24
- package/src/remote-snapshot.ts +37 -27
- package/src/serialize-worker.ts +8 -5
- package/src/sigv4-snapshot-adapter.ts +37 -27
- package/src/smart-memory-cache.ts +121 -44
- package/src/types.ts +117 -37
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/config-comparison.ts +29 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/lz4-size.ts +74 -0
- package/src/utils/namespace-key.ts +48 -0
- package/src/utils/query-key.ts +13 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/utils/snapshot-transfer.ts +83 -0
- package/src/utils/work-limits.ts +73 -0
- package/src/utils/write-revision.ts +4 -0
- package/src/wasm/bloom-filter-wasm.ts +25 -5
- package/src/worker-pool.ts +44 -15
- package/src/wtiny-lfu.ts +82 -20
- package/dist/cache-service-MG7PN6MX.js +0 -12
- package/dist/chunk-3I5L7K6I.js +0 -704
- package/dist/chunk-BQRURGGD.js +0 -60
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { KeyObject } from 'crypto';
|
|
2
2
|
|
|
3
|
+
interface SnapshotTransferOptions {
|
|
4
|
+
/** Maximum downloaded snapshot bytes, enforced while streaming. Default: 220 MiB. */
|
|
5
|
+
maxBytes?: number;
|
|
6
|
+
/** Deadline covering the request and response body. Default: 30 seconds. */
|
|
7
|
+
timeoutMs?: number;
|
|
8
|
+
}
|
|
9
|
+
interface SnapshotRequestOptions {
|
|
10
|
+
/** Cancel transport work, for example when the owning cache is destroyed. */
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
/**
|
|
4
15
|
* Encryption / obfuscation for L2 (Redis) values and disk snapshots at rest.
|
|
5
16
|
*
|
|
@@ -43,6 +54,7 @@ declare class CacheEncryption {
|
|
|
43
54
|
private _mode;
|
|
44
55
|
/** Fail-closed on invalid key material when opted in via constructor opts. */
|
|
45
56
|
private readonly _strictKeyValidation;
|
|
57
|
+
private readonly _allowLegacyPlaintextRead;
|
|
46
58
|
private _prevKey;
|
|
47
59
|
private _prevKeyObj;
|
|
48
60
|
private _prevMode;
|
|
@@ -68,6 +80,7 @@ declare class CacheEncryption {
|
|
|
68
80
|
private _xorBuffer;
|
|
69
81
|
constructor(keyBase64: string | undefined, loggerOrMode?: ILogger | EncryptionMode, mode?: EncryptionMode, previousKeyBase64?: string, previousMode?: EncryptionMode, opts?: {
|
|
70
82
|
strictKeyValidation?: boolean;
|
|
83
|
+
allowLegacyPlaintextRead?: boolean;
|
|
71
84
|
});
|
|
72
85
|
get isEnabled(): boolean;
|
|
73
86
|
get mode(): EncryptionMode;
|
|
@@ -82,6 +95,7 @@ declare class CacheEncryption {
|
|
|
82
95
|
mode: EncryptionMode;
|
|
83
96
|
prevKeyBase64: string | undefined;
|
|
84
97
|
prevMode: EncryptionMode;
|
|
98
|
+
allowLegacyPlaintextRead: boolean;
|
|
85
99
|
};
|
|
86
100
|
/**
|
|
87
101
|
* Rotate the active encryption key dynamically at runtime.
|
|
@@ -95,22 +109,23 @@ declare class CacheEncryption {
|
|
|
95
109
|
* Returns a mode-prefixed base64 string when a key is configured;
|
|
96
110
|
* otherwise returns the original string unchanged (backward-compatible).
|
|
97
111
|
*/
|
|
98
|
-
encrypt(plaintext: string): string;
|
|
112
|
+
encrypt(plaintext: string, context?: string): string;
|
|
99
113
|
/**
|
|
100
114
|
* Decrypt a Redis value.
|
|
101
115
|
* Auto-detects the envelope prefix; returns plaintext unchanged if no prefix matches.
|
|
102
116
|
* Falls back to `previousEncryptionKey` when the primary key fails (key rotation).
|
|
103
117
|
*/
|
|
104
|
-
|
|
118
|
+
assertReadPolicy(value: string | Buffer, context?: string): void;
|
|
119
|
+
decrypt(value: string, context?: string): string;
|
|
105
120
|
private _decryptWithKey;
|
|
106
121
|
/** Encrypt a raw Buffer for disk/snapshot. Returns MAGIC | payload when a key is set. */
|
|
107
|
-
encryptBuffer(data: Buffer): Buffer;
|
|
122
|
+
encryptBuffer(data: Buffer, context?: string): Buffer;
|
|
108
123
|
/**
|
|
109
124
|
* Decrypt a raw Buffer from disk/snapshot.
|
|
110
125
|
* Auto-detects the magic header; returns the original buffer if no magic matches (legacy/unencrypted).
|
|
111
126
|
* Falls back to `previousEncryptionKey` when the primary key fails (key rotation).
|
|
112
127
|
*/
|
|
113
|
-
decryptBuffer(data: Buffer): Buffer;
|
|
128
|
+
decryptBuffer(data: Buffer, context?: string): Buffer;
|
|
114
129
|
private _decryptBufferWithKey;
|
|
115
130
|
}
|
|
116
131
|
interface EnvelopeEncryptionOptions {
|
|
@@ -144,16 +159,17 @@ declare class EnvelopeEncryption {
|
|
|
144
159
|
* Enables stateless containers (Kubernetes, AWS ECS/Fargate, Google Cloud Run, Fly.io)
|
|
145
160
|
* to persist and hydrate L1 cache snapshots from remote object storage (S3, GCS, R2, Azure, MinIO, or HTTP).
|
|
146
161
|
*/
|
|
162
|
+
|
|
147
163
|
interface IRemoteSnapshotAdapter {
|
|
148
164
|
/**
|
|
149
165
|
* Read the latest snapshot blob from remote storage.
|
|
150
166
|
* Returns null if no snapshot exists yet (e.g. 404 Not Found / first deploy).
|
|
151
167
|
*/
|
|
152
|
-
get(): Promise<Buffer | Uint8Array | null>;
|
|
168
|
+
get(options?: SnapshotRequestOptions): Promise<Buffer | Uint8Array | null>;
|
|
153
169
|
/**
|
|
154
170
|
* Write the snapshot blob to remote storage.
|
|
155
171
|
*/
|
|
156
|
-
put(data: Buffer): Promise<void>;
|
|
172
|
+
put(data: Buffer, options?: SnapshotRequestOptions): Promise<void>;
|
|
157
173
|
}
|
|
158
174
|
|
|
159
175
|
interface RemoteSnapshotOptions {
|
|
@@ -184,7 +200,7 @@ interface RemoteSnapshotOptions {
|
|
|
184
200
|
*/
|
|
185
201
|
envelope?: EnvelopeEncryptionOptions;
|
|
186
202
|
}
|
|
187
|
-
interface HttpSnapshotAdapterOptions {
|
|
203
|
+
interface HttpSnapshotAdapterOptions extends SnapshotTransferOptions {
|
|
188
204
|
/**
|
|
189
205
|
* URL to fetch the snapshot from (e.g. S3 presigned GET URL or internal blob service).
|
|
190
206
|
*/
|
|
@@ -215,13 +231,6 @@ declare function createMemorySnapshotAdapter(): IRemoteSnapshotAdapter & {
|
|
|
215
231
|
clear(): void;
|
|
216
232
|
};
|
|
217
233
|
|
|
218
|
-
/**
|
|
219
|
-
* tricache — Multi-Cluster / Geo-Distributed Cross-Region Invalidation Relay
|
|
220
|
-
*
|
|
221
|
-
* Enables multi-region architectures (e.g. us-east-1 + eu-central-1) with independent
|
|
222
|
-
* Redis clusters to synchronize invalidations across regions without expensive
|
|
223
|
-
* active-active Redis Enterprise licenses.
|
|
224
|
-
*/
|
|
225
234
|
interface CrossRegionInvalidationEvent {
|
|
226
235
|
/** Unique ID of this invalidation event (UUIDv4) */
|
|
227
236
|
id: string;
|
|
@@ -237,7 +246,7 @@ interface CrossRegionInvalidationEvent {
|
|
|
237
246
|
tagVersion?: number;
|
|
238
247
|
/** Timestamp when the event was created */
|
|
239
248
|
timestamp: number;
|
|
240
|
-
/**
|
|
249
|
+
/** Exact trimmed namespace of the origin cache. Omitted means the default namespace. */
|
|
241
250
|
namespace?: string;
|
|
242
251
|
/** Optional W3C traceparent header for distributed context propagation */
|
|
243
252
|
traceparent?: string;
|
|
@@ -334,7 +343,8 @@ type CompressionAlgorithm = 'brotli' | 'gzip' | 'zstd' | 'lz4' | 'none';
|
|
|
334
343
|
interface CustomCompressor {
|
|
335
344
|
name: string;
|
|
336
345
|
compress: (buf: Buffer) => Buffer;
|
|
337
|
-
|
|
346
|
+
/** Honor maxOutputBytes during allocation; the returned size is also checked. */
|
|
347
|
+
decompress: (buf: Buffer, maxOutputBytes?: number) => Buffer;
|
|
338
348
|
}
|
|
339
349
|
/**
|
|
340
350
|
* Initializes the WebAssembly Zstandard codec.
|
|
@@ -342,6 +352,45 @@ interface CustomCompressor {
|
|
|
342
352
|
*/
|
|
343
353
|
declare function initZstd(): Promise<any>;
|
|
344
354
|
|
|
355
|
+
interface OriginCapacityOptions {
|
|
356
|
+
/** Per-process physical work budget. Batch fills reserve one slot per unique owned key. */
|
|
357
|
+
maxConcurrent: number;
|
|
358
|
+
}
|
|
359
|
+
interface OriginRunOptions {
|
|
360
|
+
signal?: AbortSignal;
|
|
361
|
+
/** Caller deadline in milliseconds; zero rejects before starting work. */
|
|
362
|
+
timeoutMs?: number;
|
|
363
|
+
/** Conservative work cost; defaults to one. No queue or implicit retry. */
|
|
364
|
+
weight?: number;
|
|
365
|
+
}
|
|
366
|
+
interface OriginCapacityMetrics {
|
|
367
|
+
active: number;
|
|
368
|
+
capacity: number;
|
|
369
|
+
rejected: number;
|
|
370
|
+
started: number;
|
|
371
|
+
completed: number;
|
|
372
|
+
cancelled: number;
|
|
373
|
+
timedOut: number;
|
|
374
|
+
closed: boolean;
|
|
375
|
+
}
|
|
376
|
+
/** Share one instance across cache loaders and the direct-origin route for the same origin. */
|
|
377
|
+
declare class OriginCapacityLimiter {
|
|
378
|
+
private readonly work;
|
|
379
|
+
private readonly pending;
|
|
380
|
+
private closed;
|
|
381
|
+
private started;
|
|
382
|
+
private completed;
|
|
383
|
+
private cancelled;
|
|
384
|
+
private timedOut;
|
|
385
|
+
constructor(options: OriginCapacityOptions);
|
|
386
|
+
run<T>(origin: (signal: AbortSignal) => T | PromiseLike<T>, options?: OriginRunOptions): Promise<T>;
|
|
387
|
+
/** Reject new work and signal active origins. Ignored cancellation still occupies capacity. */
|
|
388
|
+
close(): void;
|
|
389
|
+
metrics(): OriginCapacityMetrics;
|
|
390
|
+
/** Export once per shared origin budget, separately from per-namespace cache series. */
|
|
391
|
+
toPrometheusText(prefix?: string): string;
|
|
392
|
+
}
|
|
393
|
+
|
|
345
394
|
/**
|
|
346
395
|
* tricache — shared types and interfaces
|
|
347
396
|
*/
|
|
@@ -362,7 +411,7 @@ interface ICacheSpan {
|
|
|
362
411
|
code: 0 | 1 | 2;
|
|
363
412
|
message?: string;
|
|
364
413
|
}): this;
|
|
365
|
-
recordException?(err:
|
|
414
|
+
recordException?(err: unknown): void;
|
|
366
415
|
end(): void;
|
|
367
416
|
}
|
|
368
417
|
/**
|
|
@@ -444,8 +493,13 @@ interface SmartCacheEntry {
|
|
|
444
493
|
* Optional for backward compatibility with snapshots written by older versions.
|
|
445
494
|
*/
|
|
446
495
|
setAt?: number;
|
|
496
|
+
/** Opaque identity of this write, preserved across tiers and snapshots. */
|
|
497
|
+
revision?: string;
|
|
447
498
|
/** Active tag versions at write time (used when tagStrategy === 'generational') */
|
|
448
499
|
tagVersions?: Record<string, number>;
|
|
500
|
+
/** Set-based tags and dependency patterns preserved through disk/snapshot promotion. */
|
|
501
|
+
tags?: string[];
|
|
502
|
+
dependsOn?: string[];
|
|
449
503
|
}
|
|
450
504
|
/** Returned by SmartMemoryCache.get() — distinguishes "cached null" from a real miss */
|
|
451
505
|
interface CacheHit {
|
|
@@ -466,6 +520,9 @@ interface CacheHit {
|
|
|
466
520
|
tagVersions?: Record<string, number>;
|
|
467
521
|
/** Timestamp (ms) when this entry was written into memory */
|
|
468
522
|
setAt?: number;
|
|
523
|
+
revision?: string;
|
|
524
|
+
tags?: string[];
|
|
525
|
+
dependsOn?: string[];
|
|
469
526
|
}
|
|
470
527
|
/** On-disk entry shape (mirrors SmartCacheEntry — Uint8Array accepted for msgpack round-trips;
|
|
471
528
|
* legacy disk files written by older versions may have a JSON string in data) */
|
|
@@ -480,6 +537,13 @@ interface DiskCacheEntry {
|
|
|
480
537
|
priority: number;
|
|
481
538
|
/** Active tag versions at write time (used when tagStrategy === 'generational') */
|
|
482
539
|
tagVersions?: Record<string, number>;
|
|
540
|
+
/** Original write time and TTL, preserved on spill and promotion. */
|
|
541
|
+
setAt?: number;
|
|
542
|
+
revision?: string;
|
|
543
|
+
ttlMs?: number;
|
|
544
|
+
delta?: number;
|
|
545
|
+
tags?: string[];
|
|
546
|
+
dependsOn?: string[];
|
|
483
547
|
}
|
|
484
548
|
/**
|
|
485
549
|
* Snapshot of runtime metrics for a CacheService instance.
|
|
@@ -491,6 +555,21 @@ interface CacheMetrics {
|
|
|
491
555
|
namespace: string;
|
|
492
556
|
/** Milliseconds since the CacheService instance was constructed */
|
|
493
557
|
uptimeMs: number;
|
|
558
|
+
/** Per-cache admission accounting; active origin work remains reserved until its physical promise settles. */
|
|
559
|
+
work?: {
|
|
560
|
+
origin: {
|
|
561
|
+
active: number;
|
|
562
|
+
capacity: number;
|
|
563
|
+
rejected: number;
|
|
564
|
+
};
|
|
565
|
+
background: {
|
|
566
|
+
active: number;
|
|
567
|
+
capacity: number;
|
|
568
|
+
rejected: number;
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
/** Process-shared physical origin budget, when an OriginCapacityLimiter is configured. */
|
|
572
|
+
originCapacity?: OriginCapacityMetrics;
|
|
494
573
|
gets: {
|
|
495
574
|
total: number;
|
|
496
575
|
l1Hits: number;
|
|
@@ -524,6 +603,8 @@ interface CacheMetrics {
|
|
|
524
603
|
errors: number;
|
|
525
604
|
/** Times a later `create(ns)` call passed options diverging from the live singleton. */
|
|
526
605
|
singletonDivergences: number;
|
|
606
|
+
/** Cached reads rejected because strict invalidation protection was active. */
|
|
607
|
+
invalidationReadRejections?: number;
|
|
527
608
|
};
|
|
528
609
|
bloom: {
|
|
529
610
|
/** Total bloom-filter checks (get() calls that passed prefix filter) */
|
|
@@ -546,6 +627,18 @@ interface CacheMetrics {
|
|
|
546
627
|
backplane: {
|
|
547
628
|
enabled: boolean;
|
|
548
629
|
mode: 'pubsub' | 'stream';
|
|
630
|
+
/** True when cached values are rejected while the invalidation consumer is unavailable. */
|
|
631
|
+
readProtectionEnabled?: boolean;
|
|
632
|
+
/** Current strict-read protection state. */
|
|
633
|
+
readProtectionActive?: boolean;
|
|
634
|
+
/** Sanitized reason for the current protection state, when active. */
|
|
635
|
+
readProtectionReason?: string;
|
|
636
|
+
/** Date.now() timestamp when the current protection state began. */
|
|
637
|
+
readProtectionSince?: number | null;
|
|
638
|
+
/** Monotonic elapsed milliseconds while the read gate is closed (zero when open). */
|
|
639
|
+
readProtectionDurationMs?: number;
|
|
640
|
+
/** Configured consumer proof deadline when strict protection is enabled. */
|
|
641
|
+
readProtectionDeadlineMs?: number;
|
|
549
642
|
/** Invalidation messages published to other instances */
|
|
550
643
|
sent: number;
|
|
551
644
|
/** Invalidation messages received from other instances */
|
|
@@ -667,6 +760,18 @@ type CachePresetType = 'nextjs' | 'microservice' | 'serverless' | 'enterprise-ha
|
|
|
667
760
|
* All fields are optional — sensible defaults are used when omitted.
|
|
668
761
|
*/
|
|
669
762
|
interface CacheOptions {
|
|
763
|
+
/** Optional process-wide origin budget shared with other caches and direct-origin fallback. */
|
|
764
|
+
originCapacityLimiter?: OriginCapacityLimiter;
|
|
765
|
+
/** Maximum concurrent origin invocations (batch calls reserve one slot per owned key). Default: 1024. Saturated misses reject; no queue. */
|
|
766
|
+
maxConcurrentFetches?: number;
|
|
767
|
+
/** Maximum concurrent background refreshes, also subject to maxConcurrentFetches. Default: 64. */
|
|
768
|
+
maxBackgroundRefreshes?: number;
|
|
769
|
+
/** Maximum unique stored/pending dependency edges per instance. Default: 100000. */
|
|
770
|
+
maxDependencyEdges?: number;
|
|
771
|
+
/** Maximum outstanding serialization tasks, including pools draining during rotation. Default: 256. */
|
|
772
|
+
workerMaxPendingTasks?: number;
|
|
773
|
+
/** Outstanding worker input/context admission across rotation. Default: 64 MiB; not total process memory. */
|
|
774
|
+
workerMaxPendingBytes?: number;
|
|
670
775
|
/**
|
|
671
776
|
* Plug in your own logger (pino, winston, bunyan, …).
|
|
672
777
|
* Defaults to a minimal console logger that only prints warn/error.
|
|
@@ -697,7 +802,7 @@ interface CacheOptions {
|
|
|
697
802
|
* - `'wtinylfu'`: Window TinyLFU admission policy (popularized by Caffeine) providing
|
|
698
803
|
* mathematical scan resistance and burst recency absorption.
|
|
699
804
|
* - `'adaptive'`: Adaptive LFU x LRU x priority reservoir sampling.
|
|
700
|
-
* Default: `'wtinylfu'
|
|
805
|
+
* Default: `'adaptive'`; all built-in presets explicitly select `'wtinylfu'`.
|
|
701
806
|
*/
|
|
702
807
|
l1AdmissionPolicy?: 'wtinylfu' | 'adaptive';
|
|
703
808
|
/** Directory used for L1.5 disk-spill files. Default: os.tmpdir()/tricache-disk */
|
|
@@ -778,7 +883,7 @@ interface CacheOptions {
|
|
|
778
883
|
/**
|
|
779
884
|
* Coalesce Redis operations executed within the identical synchronous tick into a single pipeline round-trip via queueMicrotask.
|
|
780
885
|
* Eliminates syscall and network overhead under heavy concurrent traffic with 0ms event-loop delay.
|
|
781
|
-
* Default:
|
|
886
|
+
* Default: true
|
|
782
887
|
*/
|
|
783
888
|
autoPipeline?: boolean;
|
|
784
889
|
/**
|
|
@@ -854,8 +959,10 @@ interface CacheOptions {
|
|
|
854
959
|
* Has no effect when no key is configured at all (encryption stays off, by design).
|
|
855
960
|
*/
|
|
856
961
|
strictKeyValidation?: boolean;
|
|
962
|
+
/** Permit legacy context-free ciphertext/plaintext reads during a deliberate migration. Default: false. */
|
|
963
|
+
allowLegacyPlaintextRead?: boolean;
|
|
857
964
|
/**
|
|
858
|
-
* Whether to call `.toJSON()` when serializing objects
|
|
965
|
+
* Whether to call `.toJSON()` when serializing objects for packed buffers and Redis.
|
|
859
966
|
* - `true` (default): Honors `.toJSON()`, matching standard JSON serialization conventions.
|
|
860
967
|
* - `false`: Preserves the object's own internal properties (msgpackr 2.1.0+ durable state feature),
|
|
861
968
|
* avoiding accidental API response projections on cached domain entities.
|
|
@@ -884,7 +991,7 @@ interface CacheOptions {
|
|
|
884
991
|
compressionThresholdBytes?: number;
|
|
885
992
|
/**
|
|
886
993
|
* Path where the cold-start snapshot is written on SIGTERM/SIGINT and loaded
|
|
887
|
-
* on startup. Default: os.tmpdir()/tricache-snapshot
|
|
994
|
+
* on startup. Default: os.tmpdir()/tricache-snapshot-v3-<namespace-hex>.msgpack
|
|
888
995
|
*/
|
|
889
996
|
snapshotPath?: string;
|
|
890
997
|
/**
|
|
@@ -897,24 +1004,16 @@ interface CacheOptions {
|
|
|
897
1004
|
*/
|
|
898
1005
|
remoteSnapshot?: RemoteSnapshotOptions;
|
|
899
1006
|
/**
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
* L1, L1.5 (disk), and L2 (Redis). This enables:
|
|
904
|
-
* - **Multi-tenant isolation**: `CacheService.create({ namespace: 'org_abc' })`
|
|
905
|
-
* — tenants sharing the same Redis instance or disk dir are fully isolated.
|
|
906
|
-
* - **Environment separation**: `CacheService.create({ namespace: 'staging' })`
|
|
907
|
-
* - **Service-level scoping**: microservices sharing one Redis without key collisions.
|
|
908
|
-
*
|
|
909
|
-
* Consumers never see the prefix — `get('user:1')` behaves identically
|
|
910
|
-
* whether namespaced or not. Glob deletes (`delete('user:*')`) automatically
|
|
911
|
-
* scope to the namespace.
|
|
1007
|
+
* Namespace identifier used to derive collision-free, versioned storage keys
|
|
1008
|
+
* across L1, disk, Redis, invalidation, and snapshots. The identifier is trimmed.
|
|
1009
|
+
* Consumers continue to use logical keys such as `get('user:1')`.
|
|
912
1010
|
*
|
|
913
|
-
* The
|
|
914
|
-
*
|
|
915
|
-
*
|
|
1011
|
+
* The v3 format separates data, tag sets, tag versions, and locks. It does not
|
|
1012
|
+
* read earlier raw/colon-prefixed or v2 entries as a fallback. Upgrades start
|
|
1013
|
+
* cold; coordinate all writers onto v3 or isolate storage during rollout.
|
|
916
1014
|
*
|
|
917
|
-
*
|
|
1015
|
+
* Use separate Node and Edge namespaces: their value formats are not interoperable.
|
|
1016
|
+
* Default: `''` (the default namespace, also stored under the v3 format).
|
|
918
1017
|
*/
|
|
919
1018
|
namespace?: string;
|
|
920
1019
|
/**
|
|
@@ -974,6 +1073,17 @@ interface CacheOptions {
|
|
|
974
1073
|
* Default: `false` (asynchronous fire-and-forget for minimal caller latency).
|
|
975
1074
|
*/
|
|
976
1075
|
awaitInvalidationBackplane?: boolean;
|
|
1076
|
+
/**
|
|
1077
|
+
* Reject cached reads while the invalidation consumer is unavailable or has
|
|
1078
|
+
* missed its heartbeat deadline. The caller can catch
|
|
1079
|
+
* `CacheInvalidationUnavailableError` and use an authoritative origin route.
|
|
1080
|
+
* This is opt-in; `false` preserves the default availability-first behavior.
|
|
1081
|
+
* Requires active Redis/invalidation, a supported dedicated subscriber, and a
|
|
1082
|
+
* finite positive `backplaneMaxStalenessMs` detection deadline. Reads/fills
|
|
1083
|
+
* spanning a gate closure reject even if the consumer recovers meanwhile.
|
|
1084
|
+
* Strict startup skips snapshot hydration and discards existing local spill.
|
|
1085
|
+
*/
|
|
1086
|
+
rejectCachedReadsOnInvalidationLoss?: boolean;
|
|
977
1087
|
/**
|
|
978
1088
|
* If `true`, `cache.lock()` operations fail closed (throw an Error) if Redis
|
|
979
1089
|
* encounters a connection or runtime error during lock acquisition, preventing
|
|
@@ -1109,17 +1219,19 @@ interface CacheOptions {
|
|
|
1109
1219
|
frozen?: boolean;
|
|
1110
1220
|
/**
|
|
1111
1221
|
* When `true`, tricache tracks per-key fetch latency in a rolling ring buffer
|
|
1112
|
-
* and
|
|
1222
|
+
* and derives a cost-based TTL from the p95 fetch duration:
|
|
1113
1223
|
*
|
|
1114
1224
|
* ```
|
|
1115
|
-
*
|
|
1225
|
+
* adaptedTtlMs = clamp(round(p95LatencyMs × adaptiveTtlMultiplier),
|
|
1226
|
+
* adaptiveTtlMin × 1000, adaptiveTtlMax × 1000)
|
|
1116
1227
|
* ```
|
|
1117
1228
|
*
|
|
1118
1229
|
* The caller-supplied `ttlSeconds` is used until at least 5 samples are collected
|
|
1119
1230
|
* for a key, then the library takes over TTL management autonomously.
|
|
1120
1231
|
*
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
1232
|
+
* More expensive keys receive longer derived TTLs than cheaper keys, subject
|
|
1233
|
+
* to the configured bounds. Fetch latency does not establish data freshness:
|
|
1234
|
+
* choose adaptiveTtlMin/Max to match your application's stale-data tolerance.
|
|
1123
1235
|
*
|
|
1124
1236
|
* Default: `false`.
|
|
1125
1237
|
*/
|
|
@@ -1137,11 +1249,13 @@ interface CacheOptions {
|
|
|
1137
1249
|
*/
|
|
1138
1250
|
adaptiveTtlMax?: number;
|
|
1139
1251
|
/**
|
|
1140
|
-
* `p95FetchLatencyMs × adaptiveTtlMultiplier =
|
|
1252
|
+
* Dimensionless factor: `p95FetchLatencyMs × adaptiveTtlMultiplier = adaptedTtlMs`
|
|
1253
|
+
* before applying the minimum and maximum (configured in seconds).
|
|
1141
1254
|
*
|
|
1142
1255
|
* Intuition: a 200 ms p95 fetch with the default multiplier of 20 yields a
|
|
1143
|
-
* 4-second TTL
|
|
1144
|
-
*
|
|
1256
|
+
* 4-second derived TTL, raised to 10 seconds by the default minimum.
|
|
1257
|
+
* A 2 000 ms fetch yields 40 seconds. Increase the multiplier if you want
|
|
1258
|
+
* the cache to absorb more upstream pressure, within your freshness bounds.
|
|
1145
1259
|
*
|
|
1146
1260
|
* Default: `20`.
|
|
1147
1261
|
*/
|
|
@@ -1161,12 +1275,11 @@ interface CacheOptions {
|
|
|
1161
1275
|
*/
|
|
1162
1276
|
adaptiveTtlMaxKeys?: number;
|
|
1163
1277
|
/**
|
|
1164
|
-
* When `true`, tricache spawns a pool of worker threads and offloads
|
|
1165
|
-
*
|
|
1166
|
-
* V8 main event loop free for concurrent HTTP requests.
|
|
1278
|
+
* When `true`, tricache spawns a pool of worker threads and offloads
|
|
1279
|
+
* compression and encryption/decryption of large Redis payloads.
|
|
1167
1280
|
*
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1281
|
+
* MessagePack encode/decode remains on the calling thread. Compression can
|
|
1282
|
+
* run in workers even without encryption; custom compressors run locally.
|
|
1170
1283
|
*
|
|
1171
1284
|
* Default: `false`. Enable in long-running servers that write multi-megabyte
|
|
1172
1285
|
* encrypted payloads and observe event-loop latency spikes.
|
|
@@ -1195,6 +1308,9 @@ interface CacheOptions {
|
|
|
1195
1308
|
*
|
|
1196
1309
|
* Set to `0` to disable the fence entirely (accept eventual-consistency drift).
|
|
1197
1310
|
* Default: `5000` (5 seconds).
|
|
1311
|
+
* With `rejectCachedReadsOnInvalidationLoss`, this also bounds silent loss
|
|
1312
|
+
* detection since the send time of the last acknowledged consumer challenge.
|
|
1313
|
+
* Strict mode requires a finite positive value and uses monotonic elapsed time.
|
|
1198
1314
|
*/
|
|
1199
1315
|
backplaneMaxStalenessMs?: number;
|
|
1200
1316
|
/**
|
|
@@ -1330,8 +1446,8 @@ interface CacheOptions {
|
|
|
1330
1446
|
*/
|
|
1331
1447
|
backplaneStreamBlockMs?: number;
|
|
1332
1448
|
/**
|
|
1333
|
-
* Custom Redis Stream key
|
|
1334
|
-
*
|
|
1449
|
+
* Custom Redis Stream key base. TriCache adds a namespace-specific suffix so
|
|
1450
|
+
* streams remain isolated. The default is hash-tagged for Redis Cluster routing.
|
|
1335
1451
|
*/
|
|
1336
1452
|
backplaneStreamKey?: string;
|
|
1337
1453
|
/**
|
|
@@ -1363,7 +1479,11 @@ interface WrapOptions {
|
|
|
1363
1479
|
priority?: CachePriority;
|
|
1364
1480
|
/** Semantic tags for invalidation. */
|
|
1365
1481
|
tags?: string[];
|
|
1366
|
-
/**
|
|
1482
|
+
/**
|
|
1483
|
+
* Logical source-key patterns (e.g. `['user:*']`) for transitive exact-key
|
|
1484
|
+
* invalidation. Discovery uses process-local entry metadata and active writers;
|
|
1485
|
+
* it is not a shared fleet-wide dependency index.
|
|
1486
|
+
*/
|
|
1367
1487
|
dependsOn?: string[];
|
|
1368
1488
|
/** 0–1 fraction of TTL elapsed at which a proactive background refresh is scheduled. */
|
|
1369
1489
|
refreshAhead?: number;
|
|
@@ -1404,8 +1524,12 @@ interface LockOptions {
|
|
|
1404
1524
|
interface ICacheCounter {
|
|
1405
1525
|
add(value: number, attributes?: Record<string, string | number | boolean>): void;
|
|
1406
1526
|
}
|
|
1527
|
+
type ICacheObservableCallback = (result: {
|
|
1528
|
+
observe(value: number, attributes?: Record<string, string | number | boolean>): void;
|
|
1529
|
+
}) => void | Promise<void>;
|
|
1407
1530
|
interface ICacheObservableGauge {
|
|
1408
|
-
|
|
1531
|
+
addCallback(callback: ICacheObservableCallback): void;
|
|
1532
|
+
removeCallback(callback: ICacheObservableCallback): void;
|
|
1409
1533
|
}
|
|
1410
1534
|
interface ICacheBatchObservableCallback {
|
|
1411
1535
|
(observableResult: {
|
|
@@ -1422,6 +1546,7 @@ interface ICacheMeter {
|
|
|
1422
1546
|
unit?: string;
|
|
1423
1547
|
}): ICacheObservableGauge;
|
|
1424
1548
|
addBatchObservableCallback(callback: ICacheBatchObservableCallback, observables: ICacheObservableGauge[]): void;
|
|
1549
|
+
removeBatchObservableCallback?(callback: ICacheBatchObservableCallback, observables: ICacheObservableGauge[]): void;
|
|
1425
1550
|
}
|
|
1426
1551
|
/**
|
|
1427
1552
|
* Common pipeline / transaction interface matching ioredis and adapted drivers.
|
|
@@ -1437,6 +1562,9 @@ interface IRedisPipeline {
|
|
|
1437
1562
|
smembers(key: string): this;
|
|
1438
1563
|
hset(key: string, value: Record<string, string>): this;
|
|
1439
1564
|
hgetall?(key: string): this;
|
|
1565
|
+
/** Remaining TTL in milliseconds; enables atomic value + expiry reads. */
|
|
1566
|
+
pttl?(key: string): this;
|
|
1567
|
+
eval?(script: string, numkeys: number, ...args: (string | number)[]): this;
|
|
1440
1568
|
exec(): Promise<Array<[Error | null, any]> | null>;
|
|
1441
1569
|
}
|
|
1442
1570
|
/**
|
|
@@ -1449,6 +1577,7 @@ interface IRedisDriver {
|
|
|
1449
1577
|
setex?(key: string, seconds: number, value: string): Promise<unknown>;
|
|
1450
1578
|
del(...keys: string[]): Promise<number>;
|
|
1451
1579
|
ping(): Promise<string>;
|
|
1580
|
+
pttl?(key: string): Promise<number>;
|
|
1452
1581
|
expire(key: string, seconds: number): Promise<number | boolean>;
|
|
1453
1582
|
incr(key: string): Promise<number>;
|
|
1454
1583
|
eval(script: string, numkeys: number, ...args: (string | number)[]): Promise<unknown>;
|
|
@@ -1462,9 +1591,12 @@ interface IRedisDriver {
|
|
|
1462
1591
|
count?: number;
|
|
1463
1592
|
}): any;
|
|
1464
1593
|
hset?(key: string, value: Record<string, string>): Promise<unknown>;
|
|
1594
|
+
/** Enables tagged hash envelopes, preserving tags/deadlines on cold reads and touch(). */
|
|
1465
1595
|
hgetall?(key: string): Promise<Record<string, string>>;
|
|
1466
1596
|
publish?(channel: string, message: string): Promise<number>;
|
|
1467
1597
|
subscribe?(...channels: string[]): Promise<unknown>;
|
|
1598
|
+
unsubscribe?(...channels: string[]): Promise<unknown>;
|
|
1599
|
+
removeListener?(event: string, listener: (...args: any[]) => void): this | unknown;
|
|
1468
1600
|
disconnect(): Promise<void> | void;
|
|
1469
1601
|
quit?(): Promise<void> | void;
|
|
1470
1602
|
duplicate?(): IRedisDriver;
|
|
@@ -1501,4 +1633,4 @@ interface WTinyLfuStats {
|
|
|
1501
1633
|
promotions: number;
|
|
1502
1634
|
}
|
|
1503
1635
|
|
|
1504
|
-
export { type
|
|
1636
|
+
export { createMemoryCrossRegionRelay as $, type ICacheCounter as A, type ICacheMeter as B, type CacheOptions as C, type DiskBackpressureStats as D, type EncryptionMode as E, type ICacheObservableGauge as F, type ICacheSpan as G, type HttpMeshRelayOptions as H, type ICacheTracer as I, type ICacheSpanLink as J, type ICrossRegionRelay as K, type LockOptions as L, type OriginCapacityMetrics as M, type OriginCapacityOptions as N, OriginCapacityLimiter as O, type OriginRunOptions as P, type WebhookRequestLike as Q, type RemoteSnapshotOptions as R, type SnapshotTransferOptions as S, type WebhookResponseLike as T, consoleLogger as U, createCrossRegionWebhookHandler as V, type WrapOptions as W, createCustomCrossRegionRelay as X, createCustomSnapshotAdapter as Y, createHttpMeshRelay as Z, createHttpSnapshotAdapter as _, type InvalidateTagOptions as a, createMemorySnapshotAdapter as a0, initZstd as a1, type CacheMetrics as b, type CacheHealthStatus as c, type CachePresetType as d, type CrossRegionInvalidationEvent as e, CachePriority as f, type CachePingResult as g, type WTinyLfuStats as h, type ILogger as i, type IRemoteSnapshotAdapter as j, type SnapshotRequestOptions as k, type CategoryLimit as l, type SmartCacheEntry as m, type EvictionReason as n, type CacheHit as o, CacheEncryption as p, type CompressionAlgorithm as q, type DiskCacheEntry as r, type IRedisDriver as s, type IRedisPipeline as t, type CrossRegionRelayOptions as u, type CustomCompressor as v, EnvelopeEncryption as w, type EnvelopeEncryptionOptions as x, type HttpSnapshotAdapterOptions as y, type ICacheBatchObservableCallback as z };
|