tricache 1.0.2 → 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 +78 -90
- 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-CWI4jkS7.d.cts → cache-service-BV5T8-20.d.cts} +122 -21
- package/dist/cache-service-UZXOQGEY.js +14 -0
- package/dist/{cache-service-B108FzER.d.ts → cache-service-tpyrXvlH.d.ts} +122 -21
- package/dist/{chunk-UBWLPKTI.js → chunk-EJXG7WO6.js} +152 -32
- package/dist/{chunk-H4GFLQ26.js → chunk-KV7KISK2.js} +47 -1
- package/dist/{chunk-WYF7NOAT.js → chunk-MB3DMVWN.js} +2111 -543
- package/dist/{chunk-OYDU3SMI.js → chunk-RBJRTGFK.js} +5 -0
- package/dist/chunk-S5N65I45.js +17 -0
- package/dist/cli.cjs +2454 -572
- package/dist/cli.js +186 -11
- package/dist/dashboard/index.d.cts +2 -2
- package/dist/dashboard/index.d.ts +2 -2
- package/dist/drizzle/index.cjs +2335 -571
- package/dist/drizzle/index.d.cts +2 -2
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +6 -2
- package/dist/edge/index.cjs +145 -43
- package/dist/edge/index.d.cts +11 -4
- package/dist/edge/index.d.ts +11 -4
- package/dist/edge/index.js +118 -43
- package/dist/hono/index.cjs +2322 -569
- package/dist/hono/index.d.cts +2 -2
- package/dist/hono/index.d.ts +2 -2
- package/dist/hono/index.js +2 -2
- package/dist/{hono-C886ok3X.d.cts → hono-CMv2VdQ6.d.cts} +18 -5
- package/dist/{hono-3rDMYVtY.d.ts → hono-Dvq04kX9.d.ts} +18 -5
- package/dist/http/index.cjs +2323 -570
- package/dist/http/index.d.cts +3 -3
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +4 -4
- package/dist/index.cjs +2554 -620
- package/dist/index.d.cts +88 -23
- package/dist/index.d.ts +88 -23
- package/dist/index.js +873 -16
- package/dist/{murmur3-CMGw9PbV.d.cts → murmur3-DF8BFRnu.d.cts} +1 -0
- package/dist/{murmur3-CMGw9PbV.d.ts → murmur3-DF8BFRnu.d.ts} +1 -0
- package/dist/nestjs/index.cjs +2292 -574
- package/dist/nestjs/index.d.cts +19 -5
- package/dist/nestjs/index.d.ts +19 -5
- package/dist/nestjs/index.js +25 -19
- package/dist/next/index.cjs +2306 -571
- package/dist/next/index.d.cts +8 -2
- package/dist/next/index.d.ts +8 -2
- package/dist/next/index.js +36 -9
- package/dist/prisma/index.cjs +26 -25
- package/dist/prisma/index.d.cts +2 -2
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +14 -25
- package/dist/serialize-worker.cjs +162 -39
- package/dist/serialize-worker.js +9 -7
- package/dist/{types-BA4pz1A0.d.cts → types-F8vRWMrE.d.cts} +162 -45
- package/dist/{types-BA4pz1A0.d.ts → types-F8vRWMrE.d.ts} +162 -45
- package/package.json +21 -2
- package/src/adapters/auto-pipeliner.ts +52 -11
- package/src/cache-service.ts +1537 -415
- package/src/cli.ts +2 -9
- package/src/codec.ts +3 -3
- package/src/compression.ts +39 -16
- package/src/cross-region.ts +1 -1
- package/src/disk-tier.ts +283 -43
- 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 +59 -17
- package/src/edge/types.ts +15 -5
- package/src/encryption.ts +50 -18
- package/src/env.d.ts +1 -1
- package/src/errors.ts +12 -0
- package/src/http/utils.ts +6 -0
- package/src/index.ts +6 -0
- package/src/latency-watchdog.ts +5 -1
- package/src/nestjs/decorators.ts +11 -6
- package/src/nestjs/tricache.module.ts +2 -1
- package/src/nestjs/tricache.store.ts +21 -9
- package/src/nestjs/types.ts +1 -1
- package/src/next/cache-handler.ts +24 -4
- package/src/next/types.ts +4 -0
- package/src/origin-capacity.ts +134 -0
- package/src/prisma/index.ts +14 -32
- 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 +62 -22
- package/src/types.ts +92 -35
- package/src/utils/config-comparison.ts +29 -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/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 +16 -1
- package/src/worker-pool.ts +28 -8
- package/src/wtiny-lfu.ts +62 -14
- package/dist/cache-service-GYPZFB7O.js +0 -12
- package/dist/chunk-VNRDL5RA.js +0 -666
|
@@ -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
|
*/
|
|
@@ -230,7 +246,7 @@ interface CrossRegionInvalidationEvent {
|
|
|
230
246
|
tagVersion?: number;
|
|
231
247
|
/** Timestamp when the event was created */
|
|
232
248
|
timestamp: number;
|
|
233
|
-
/**
|
|
249
|
+
/** Exact trimmed namespace of the origin cache. Omitted means the default namespace. */
|
|
234
250
|
namespace?: string;
|
|
235
251
|
/** Optional W3C traceparent header for distributed context propagation */
|
|
236
252
|
traceparent?: string;
|
|
@@ -327,7 +343,8 @@ type CompressionAlgorithm = 'brotli' | 'gzip' | 'zstd' | 'lz4' | 'none';
|
|
|
327
343
|
interface CustomCompressor {
|
|
328
344
|
name: string;
|
|
329
345
|
compress: (buf: Buffer) => Buffer;
|
|
330
|
-
|
|
346
|
+
/** Honor maxOutputBytes during allocation; the returned size is also checked. */
|
|
347
|
+
decompress: (buf: Buffer, maxOutputBytes?: number) => Buffer;
|
|
331
348
|
}
|
|
332
349
|
/**
|
|
333
350
|
* Initializes the WebAssembly Zstandard codec.
|
|
@@ -335,6 +352,45 @@ interface CustomCompressor {
|
|
|
335
352
|
*/
|
|
336
353
|
declare function initZstd(): Promise<any>;
|
|
337
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
|
+
|
|
338
394
|
/**
|
|
339
395
|
* tricache — shared types and interfaces
|
|
340
396
|
*/
|
|
@@ -437,6 +493,8 @@ interface SmartCacheEntry {
|
|
|
437
493
|
* Optional for backward compatibility with snapshots written by older versions.
|
|
438
494
|
*/
|
|
439
495
|
setAt?: number;
|
|
496
|
+
/** Opaque identity of this write, preserved across tiers and snapshots. */
|
|
497
|
+
revision?: string;
|
|
440
498
|
/** Active tag versions at write time (used when tagStrategy === 'generational') */
|
|
441
499
|
tagVersions?: Record<string, number>;
|
|
442
500
|
/** Set-based tags and dependency patterns preserved through disk/snapshot promotion. */
|
|
@@ -462,6 +520,7 @@ interface CacheHit {
|
|
|
462
520
|
tagVersions?: Record<string, number>;
|
|
463
521
|
/** Timestamp (ms) when this entry was written into memory */
|
|
464
522
|
setAt?: number;
|
|
523
|
+
revision?: string;
|
|
465
524
|
tags?: string[];
|
|
466
525
|
dependsOn?: string[];
|
|
467
526
|
}
|
|
@@ -480,6 +539,7 @@ interface DiskCacheEntry {
|
|
|
480
539
|
tagVersions?: Record<string, number>;
|
|
481
540
|
/** Original write time and TTL, preserved on spill and promotion. */
|
|
482
541
|
setAt?: number;
|
|
542
|
+
revision?: string;
|
|
483
543
|
ttlMs?: number;
|
|
484
544
|
delta?: number;
|
|
485
545
|
tags?: string[];
|
|
@@ -495,6 +555,21 @@ interface CacheMetrics {
|
|
|
495
555
|
namespace: string;
|
|
496
556
|
/** Milliseconds since the CacheService instance was constructed */
|
|
497
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;
|
|
498
573
|
gets: {
|
|
499
574
|
total: number;
|
|
500
575
|
l1Hits: number;
|
|
@@ -528,6 +603,8 @@ interface CacheMetrics {
|
|
|
528
603
|
errors: number;
|
|
529
604
|
/** Times a later `create(ns)` call passed options diverging from the live singleton. */
|
|
530
605
|
singletonDivergences: number;
|
|
606
|
+
/** Cached reads rejected because strict invalidation protection was active. */
|
|
607
|
+
invalidationReadRejections?: number;
|
|
531
608
|
};
|
|
532
609
|
bloom: {
|
|
533
610
|
/** Total bloom-filter checks (get() calls that passed prefix filter) */
|
|
@@ -550,6 +627,18 @@ interface CacheMetrics {
|
|
|
550
627
|
backplane: {
|
|
551
628
|
enabled: boolean;
|
|
552
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;
|
|
553
642
|
/** Invalidation messages published to other instances */
|
|
554
643
|
sent: number;
|
|
555
644
|
/** Invalidation messages received from other instances */
|
|
@@ -671,6 +760,18 @@ type CachePresetType = 'nextjs' | 'microservice' | 'serverless' | 'enterprise-ha
|
|
|
671
760
|
* All fields are optional — sensible defaults are used when omitted.
|
|
672
761
|
*/
|
|
673
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;
|
|
674
775
|
/**
|
|
675
776
|
* Plug in your own logger (pino, winston, bunyan, …).
|
|
676
777
|
* Defaults to a minimal console logger that only prints warn/error.
|
|
@@ -701,7 +802,7 @@ interface CacheOptions {
|
|
|
701
802
|
* - `'wtinylfu'`: Window TinyLFU admission policy (popularized by Caffeine) providing
|
|
702
803
|
* mathematical scan resistance and burst recency absorption.
|
|
703
804
|
* - `'adaptive'`: Adaptive LFU x LRU x priority reservoir sampling.
|
|
704
|
-
* Default: `'wtinylfu'
|
|
805
|
+
* Default: `'adaptive'`; all built-in presets explicitly select `'wtinylfu'`.
|
|
705
806
|
*/
|
|
706
807
|
l1AdmissionPolicy?: 'wtinylfu' | 'adaptive';
|
|
707
808
|
/** Directory used for L1.5 disk-spill files. Default: os.tmpdir()/tricache-disk */
|
|
@@ -782,7 +883,7 @@ interface CacheOptions {
|
|
|
782
883
|
/**
|
|
783
884
|
* Coalesce Redis operations executed within the identical synchronous tick into a single pipeline round-trip via queueMicrotask.
|
|
784
885
|
* Eliminates syscall and network overhead under heavy concurrent traffic with 0ms event-loop delay.
|
|
785
|
-
* Default:
|
|
886
|
+
* Default: true
|
|
786
887
|
*/
|
|
787
888
|
autoPipeline?: boolean;
|
|
788
889
|
/**
|
|
@@ -858,8 +959,10 @@ interface CacheOptions {
|
|
|
858
959
|
* Has no effect when no key is configured at all (encryption stays off, by design).
|
|
859
960
|
*/
|
|
860
961
|
strictKeyValidation?: boolean;
|
|
962
|
+
/** Permit legacy context-free ciphertext/plaintext reads during a deliberate migration. Default: false. */
|
|
963
|
+
allowLegacyPlaintextRead?: boolean;
|
|
861
964
|
/**
|
|
862
|
-
* Whether to call `.toJSON()` when serializing objects
|
|
965
|
+
* Whether to call `.toJSON()` when serializing objects for packed buffers and Redis.
|
|
863
966
|
* - `true` (default): Honors `.toJSON()`, matching standard JSON serialization conventions.
|
|
864
967
|
* - `false`: Preserves the object's own internal properties (msgpackr 2.1.0+ durable state feature),
|
|
865
968
|
* avoiding accidental API response projections on cached domain entities.
|
|
@@ -888,7 +991,7 @@ interface CacheOptions {
|
|
|
888
991
|
compressionThresholdBytes?: number;
|
|
889
992
|
/**
|
|
890
993
|
* Path where the cold-start snapshot is written on SIGTERM/SIGINT and loaded
|
|
891
|
-
* on startup. Default: os.tmpdir()/tricache-snapshot
|
|
994
|
+
* on startup. Default: os.tmpdir()/tricache-snapshot-v3-<namespace-hex>.msgpack
|
|
892
995
|
*/
|
|
893
996
|
snapshotPath?: string;
|
|
894
997
|
/**
|
|
@@ -901,24 +1004,16 @@ interface CacheOptions {
|
|
|
901
1004
|
*/
|
|
902
1005
|
remoteSnapshot?: RemoteSnapshotOptions;
|
|
903
1006
|
/**
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
* L1, L1.5 (disk), and L2 (Redis). This enables:
|
|
908
|
-
* - **Multi-tenant isolation**: `CacheService.create({ namespace: 'org_abc' })`
|
|
909
|
-
* — tenants sharing the same Redis instance or disk dir are fully isolated.
|
|
910
|
-
* - **Environment separation**: `CacheService.create({ namespace: 'staging' })`
|
|
911
|
-
* - **Service-level scoping**: microservices sharing one Redis without key collisions.
|
|
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
|
-
*
|
|
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
|
-
*
|
|
918
|
-
*
|
|
919
|
-
* with different namespaces return completely independent instances.
|
|
920
|
-
*
|
|
921
|
-
* Default: `''` (no prefix)
|
|
1015
|
+
* Use separate Node and Edge namespaces: their value formats are not interoperable.
|
|
1016
|
+
* Default: `''` (the default namespace, also stored under the v3 format).
|
|
922
1017
|
*/
|
|
923
1018
|
namespace?: string;
|
|
924
1019
|
/**
|
|
@@ -978,6 +1073,17 @@ interface CacheOptions {
|
|
|
978
1073
|
* Default: `false` (asynchronous fire-and-forget for minimal caller latency).
|
|
979
1074
|
*/
|
|
980
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;
|
|
981
1087
|
/**
|
|
982
1088
|
* If `true`, `cache.lock()` operations fail closed (throw an Error) if Redis
|
|
983
1089
|
* encounters a connection or runtime error during lock acquisition, preventing
|
|
@@ -1113,17 +1219,19 @@ interface CacheOptions {
|
|
|
1113
1219
|
frozen?: boolean;
|
|
1114
1220
|
/**
|
|
1115
1221
|
* When `true`, tricache tracks per-key fetch latency in a rolling ring buffer
|
|
1116
|
-
* and
|
|
1222
|
+
* and derives a cost-based TTL from the p95 fetch duration:
|
|
1117
1223
|
*
|
|
1118
1224
|
* ```
|
|
1119
|
-
*
|
|
1225
|
+
* adaptedTtlMs = clamp(round(p95LatencyMs × adaptiveTtlMultiplier),
|
|
1226
|
+
* adaptiveTtlMin × 1000, adaptiveTtlMax × 1000)
|
|
1120
1227
|
* ```
|
|
1121
1228
|
*
|
|
1122
1229
|
* The caller-supplied `ttlSeconds` is used until at least 5 samples are collected
|
|
1123
1230
|
* for a key, then the library takes over TTL management autonomously.
|
|
1124
1231
|
*
|
|
1125
|
-
*
|
|
1126
|
-
*
|
|
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.
|
|
1127
1235
|
*
|
|
1128
1236
|
* Default: `false`.
|
|
1129
1237
|
*/
|
|
@@ -1141,11 +1249,13 @@ interface CacheOptions {
|
|
|
1141
1249
|
*/
|
|
1142
1250
|
adaptiveTtlMax?: number;
|
|
1143
1251
|
/**
|
|
1144
|
-
* `p95FetchLatencyMs × adaptiveTtlMultiplier =
|
|
1252
|
+
* Dimensionless factor: `p95FetchLatencyMs × adaptiveTtlMultiplier = adaptedTtlMs`
|
|
1253
|
+
* before applying the minimum and maximum (configured in seconds).
|
|
1145
1254
|
*
|
|
1146
1255
|
* Intuition: a 200 ms p95 fetch with the default multiplier of 20 yields a
|
|
1147
|
-
* 4-second TTL
|
|
1148
|
-
*
|
|
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.
|
|
1149
1259
|
*
|
|
1150
1260
|
* Default: `20`.
|
|
1151
1261
|
*/
|
|
@@ -1165,12 +1275,11 @@ interface CacheOptions {
|
|
|
1165
1275
|
*/
|
|
1166
1276
|
adaptiveTtlMaxKeys?: number;
|
|
1167
1277
|
/**
|
|
1168
|
-
* When `true`, tricache spawns a pool of worker threads and offloads
|
|
1169
|
-
*
|
|
1170
|
-
* 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.
|
|
1171
1280
|
*
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1281
|
+
* MessagePack encode/decode remains on the calling thread. Compression can
|
|
1282
|
+
* run in workers even without encryption; custom compressors run locally.
|
|
1174
1283
|
*
|
|
1175
1284
|
* Default: `false`. Enable in long-running servers that write multi-megabyte
|
|
1176
1285
|
* encrypted payloads and observe event-loop latency spikes.
|
|
@@ -1199,6 +1308,9 @@ interface CacheOptions {
|
|
|
1199
1308
|
*
|
|
1200
1309
|
* Set to `0` to disable the fence entirely (accept eventual-consistency drift).
|
|
1201
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.
|
|
1202
1314
|
*/
|
|
1203
1315
|
backplaneMaxStalenessMs?: number;
|
|
1204
1316
|
/**
|
|
@@ -1334,8 +1446,8 @@ interface CacheOptions {
|
|
|
1334
1446
|
*/
|
|
1335
1447
|
backplaneStreamBlockMs?: number;
|
|
1336
1448
|
/**
|
|
1337
|
-
* Custom Redis Stream key
|
|
1338
|
-
*
|
|
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.
|
|
1339
1451
|
*/
|
|
1340
1452
|
backplaneStreamKey?: string;
|
|
1341
1453
|
/**
|
|
@@ -1367,7 +1479,11 @@ interface WrapOptions {
|
|
|
1367
1479
|
priority?: CachePriority;
|
|
1368
1480
|
/** Semantic tags for invalidation. */
|
|
1369
1481
|
tags?: string[];
|
|
1370
|
-
/**
|
|
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
|
+
*/
|
|
1371
1487
|
dependsOn?: string[];
|
|
1372
1488
|
/** 0–1 fraction of TTL elapsed at which a proactive background refresh is scheduled. */
|
|
1373
1489
|
refreshAhead?: number;
|
|
@@ -1475,6 +1591,7 @@ interface IRedisDriver {
|
|
|
1475
1591
|
count?: number;
|
|
1476
1592
|
}): any;
|
|
1477
1593
|
hset?(key: string, value: Record<string, string>): Promise<unknown>;
|
|
1594
|
+
/** Enables tagged hash envelopes, preserving tags/deadlines on cold reads and touch(). */
|
|
1478
1595
|
hgetall?(key: string): Promise<Record<string, string>>;
|
|
1479
1596
|
publish?(channel: string, message: string): Promise<number>;
|
|
1480
1597
|
subscribe?(...channels: string[]): Promise<unknown>;
|
|
@@ -1516,4 +1633,4 @@ interface WTinyLfuStats {
|
|
|
1516
1633
|
promotions: number;
|
|
1517
1634
|
}
|
|
1518
1635
|
|
|
1519
|
-
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 };
|