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
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { C as CacheService, I as IIpcCacheProvider, a as IpcMetricsPayload, b as IpcTelemetryClient, c as IpcTelemetryServer, L as LatencyWatchdogOptions, d as LatencyWatchdogTelemetry, P as ProcessTerminationBus, T as TierLatencyWatchdog, e as deepMergeOptions, f as findActiveSockets, g as formatBytes, h as formatDuration, i as formatNumber, r as renderProgressBar, j as renderTopDashboard, k as resolveIpcSocketPath } from './cache-service-
|
|
2
|
-
import { j as IRemoteSnapshotAdapter, k as CategoryLimit,
|
|
3
|
-
export { c as CacheHealthStatus, b as CacheMetrics, C as CacheOptions, g as CachePingResult, d as CachePresetType, e as CrossRegionInvalidationEvent,
|
|
4
|
-
export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from './murmur3-
|
|
1
|
+
export { C as CacheService, I as IIpcCacheProvider, a as IpcMetricsPayload, b as IpcTelemetryClient, c as IpcTelemetryServer, L as LatencyWatchdogOptions, d as LatencyWatchdogTelemetry, P as ProcessTerminationBus, T as TierLatencyWatchdog, e as deepMergeOptions, f as findActiveSockets, g as formatBytes, h as formatDuration, i as formatNumber, r as renderProgressBar, j as renderTopDashboard, k as resolveIpcSocketPath } from './cache-service-tpyrXvlH.js';
|
|
2
|
+
import { j as IRemoteSnapshotAdapter, S as SnapshotTransferOptions, k as SnapshotRequestOptions, l as CategoryLimit, m as SmartCacheEntry, n as EvictionReason, i as ILogger, o as CacheHit, f as CachePriority, h as WTinyLfuStats$1, p as CacheEncryption, q as CompressionAlgorithm, r as DiskCacheEntry, D as DiskBackpressureStats, s as IRedisDriver, t as IRedisPipeline } from './types-F8vRWMrE.js';
|
|
3
|
+
export { c as CacheHealthStatus, b as CacheMetrics, C as CacheOptions, g as CachePingResult, d as CachePresetType, e as CrossRegionInvalidationEvent, u as CrossRegionRelayOptions, v as CustomCompressor, E as EncryptionMode, w as EnvelopeEncryption, x as EnvelopeEncryptionOptions, H as HttpMeshRelayOptions, y as HttpSnapshotAdapterOptions, z as ICacheBatchObservableCallback, A as ICacheCounter, B as ICacheMeter, F as ICacheObservableGauge, G as ICacheSpan, J as ICacheSpanLink, I as ICacheTracer, K as ICrossRegionRelay, a as InvalidateTagOptions, L as LockOptions, O as OriginCapacityLimiter, M as OriginCapacityMetrics, N as OriginCapacityOptions, P as OriginRunOptions, R as RemoteSnapshotOptions, Q as WebhookRequestLike, T as WebhookResponseLike, W as WrapOptions, U as consoleLogger, V as createCrossRegionWebhookHandler, X as createCustomCrossRegionRelay, Y as createCustomSnapshotAdapter, Z as createHttpMeshRelay, _ as createHttpSnapshotAdapter, $ as createMemoryCrossRegionRelay, a0 as createMemorySnapshotAdapter, a1 as initZstd } from './types-F8vRWMrE.js';
|
|
4
|
+
export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from './murmur3-DF8BFRnu.js';
|
|
5
5
|
import { EventEmitter } from 'node:events';
|
|
6
6
|
export { DashboardActionEvent, DashboardOptions, DashboardPeerInstance, StandaloneDashboardOptions, createNextDashboardHandlers, handleDashboardRequest, startDashboardServer, tricacheDashboard } from './dashboard/index.js';
|
|
7
7
|
import 'crypto';
|
|
@@ -18,7 +18,7 @@ import 'node:http';
|
|
|
18
18
|
* or custom S3-compatible object storage WITHOUT pulling in the 30MB @aws-sdk/client-s3.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
interface SigV4SnapshotAdapterOptions {
|
|
21
|
+
interface SigV4SnapshotAdapterOptions extends SnapshotTransferOptions {
|
|
22
22
|
/** S3 or Cloudflare R2 bucket name */
|
|
23
23
|
bucket: string;
|
|
24
24
|
/** Object key / filename for the snapshot (e.g. 'production-l1.snap') */
|
|
@@ -48,11 +48,12 @@ declare class SigV4SnapshotAdapter implements IRemoteSnapshotAdapter {
|
|
|
48
48
|
private readonly sessionToken?;
|
|
49
49
|
private readonly forcePathStyle;
|
|
50
50
|
private readonly fetchImpl;
|
|
51
|
+
private readonly transfer;
|
|
51
52
|
constructor(options: SigV4SnapshotAdapterOptions);
|
|
52
53
|
private _resolveTarget;
|
|
53
54
|
private _buildHeaders;
|
|
54
|
-
get(): Promise<Buffer | null>;
|
|
55
|
-
put(data: Buffer): Promise<void>;
|
|
55
|
+
get(request?: SnapshotRequestOptions): Promise<Buffer | null>;
|
|
56
|
+
put(data: Buffer, request?: SnapshotRequestOptions): Promise<void>;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* Creates a zero-dependency AWS SigV4 snapshot adapter for AWS S3, Cloudflare R2, MinIO, or custom gateways.
|
|
@@ -92,13 +93,13 @@ interface CacheCodecOptions {
|
|
|
92
93
|
moreTypes?: boolean;
|
|
93
94
|
/**
|
|
94
95
|
* Decode MessagePack maps as plain JavaScript objects.
|
|
95
|
-
* Default:
|
|
96
|
+
* Default: false (preserves Map; record-encoded plain objects remain objects).
|
|
96
97
|
*/
|
|
97
98
|
mapsAsObjects?: boolean;
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
100
101
|
* CacheCodec wraps msgpackr's Packr/Unpackr to provide unified, high-performance binary
|
|
101
|
-
* serialization across L1 in-memory buffers, L1.5 disk spill, and cold-start snapshots.
|
|
102
|
+
* serialization across L1 in-memory buffers, L1.5 disk spill, Redis, and cold-start snapshots.
|
|
102
103
|
*/
|
|
103
104
|
declare class CacheCodec {
|
|
104
105
|
private readonly packr;
|
|
@@ -135,6 +136,8 @@ interface SmartMemoryCacheOptions {
|
|
|
135
136
|
maxBytes: number;
|
|
136
137
|
maxEntries: number;
|
|
137
138
|
categories: Record<string, CategoryLimit>;
|
|
139
|
+
/** Storage-key prefix to skip when matching logical category prefixes. */
|
|
140
|
+
keyPrefixLength?: number;
|
|
138
141
|
diskSpill?: (key: string, entry: SmartCacheEntry) => void | Promise<void>;
|
|
139
142
|
onEviction?: (key: string, reason: EvictionReason) => void;
|
|
140
143
|
logger: ILogger;
|
|
@@ -167,6 +170,7 @@ declare class SmartMemoryCache {
|
|
|
167
170
|
private categoryKeys;
|
|
168
171
|
private bloomChecks;
|
|
169
172
|
private bloomFalsePos;
|
|
173
|
+
private bloomAbsentChecks;
|
|
170
174
|
private compressions;
|
|
171
175
|
private categoryHits;
|
|
172
176
|
/** Counts every _delete() call — used to trigger bloom rebuild from ALL deletion paths. */
|
|
@@ -203,7 +207,16 @@ declare class SmartMemoryCache {
|
|
|
203
207
|
private maybeRebuildBloom;
|
|
204
208
|
private smartEvict;
|
|
205
209
|
get(key: string): CacheHit | null;
|
|
206
|
-
|
|
210
|
+
/** Shared policy accounting for scalar and batch reads. */
|
|
211
|
+
recordAccess(key: string, entry: SmartCacheEntry, now?: number): void;
|
|
212
|
+
set(key: string, data: unknown, ttlMs: number, priority?: CachePriority, staleAt?: number, delta?: number, tagVersions?: Record<string, number>, setAt?: number, tags?: string[], dependsOn?: string[], revision?: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Store a value when its codec representation is already available.
|
|
215
|
+
* CacheService uses this to share one MessagePack encoding between L1 and
|
|
216
|
+
* Redis/disk writes on an origin fill. The buffer is treated as immutable.
|
|
217
|
+
*/
|
|
218
|
+
setPacked(key: string, packed: Buffer, data: unknown, ttlMs: number, priority?: CachePriority, staleAt?: number, delta?: number, tagVersions?: Record<string, number>, setAt?: number, tags?: string[], dependsOn?: string[], revision?: string): boolean;
|
|
219
|
+
private storePacked;
|
|
207
220
|
delete(key: string): boolean;
|
|
208
221
|
private keysMatchingPattern;
|
|
209
222
|
deletePattern(pattern: string): number;
|
|
@@ -230,7 +243,7 @@ declare class SmartMemoryCache {
|
|
|
230
243
|
evictPercentage(pct: number): number;
|
|
231
244
|
cleanup(): number;
|
|
232
245
|
/**
|
|
233
|
-
* Evict all
|
|
246
|
+
* Evict all L1 entries that were written before `cutoffMs`, at every priority.
|
|
234
247
|
*
|
|
235
248
|
* Called by the backplane staleness fence when the Pub/Sub subscriber
|
|
236
249
|
* reconnects after a disconnect gap that exceeded `backplaneMaxStalenessMs`.
|
|
@@ -249,10 +262,11 @@ declare class SmartMemoryCache {
|
|
|
249
262
|
evictSetBefore(cutoffMs: number): number;
|
|
250
263
|
/**
|
|
251
264
|
* Delete a key only if its write timestamp (`setAt`) is <= `cutoffMs`.
|
|
252
|
-
*
|
|
253
|
-
* guaranteeing that a newer value written by a concurrent revalidation is never wiped out.
|
|
265
|
+
* This is a time-based eviction policy; use deleteIfRevision for write identity.
|
|
254
266
|
*/
|
|
255
267
|
deleteIfSetBefore(key: string, cutoffMs: number): boolean;
|
|
268
|
+
/** Remove exactly the observed write, even when another write shares its timestamp. */
|
|
269
|
+
deleteIfRevision(key: string, revision: string): boolean;
|
|
256
270
|
exportEntries(forbiddenPrefixes: readonly string[]): Array<{
|
|
257
271
|
key: string;
|
|
258
272
|
entry: SmartCacheEntry;
|
|
@@ -315,6 +329,7 @@ declare class SmartMemoryCache {
|
|
|
315
329
|
bloom: {
|
|
316
330
|
checks: number;
|
|
317
331
|
falsePositives: number;
|
|
332
|
+
absentChecks: number;
|
|
318
333
|
};
|
|
319
334
|
compression: {
|
|
320
335
|
compressed: number;
|
|
@@ -341,7 +356,7 @@ declare class SmartMemoryCache {
|
|
|
341
356
|
* Add additional milliseconds to a key's existing expiry (for stale-if-error).
|
|
342
357
|
* Returns `false` if the key is absent or already expired.
|
|
343
358
|
*/
|
|
344
|
-
bumpExpiry(key: string, additionalMs: number): boolean;
|
|
359
|
+
bumpExpiry(key: string, additionalMs: number, maximumExpiry?: number): boolean;
|
|
345
360
|
bloomMightContain(key: string): boolean;
|
|
346
361
|
bloomStats(): {
|
|
347
362
|
bitsSet: number;
|
|
@@ -528,6 +543,7 @@ interface WTinyLfuAdmissionDecision {
|
|
|
528
543
|
*/
|
|
529
544
|
declare class WTinyLfuPolicy {
|
|
530
545
|
private readonly sketch;
|
|
546
|
+
private readonly canEvict?;
|
|
531
547
|
private readonly maxTotal;
|
|
532
548
|
private readonly maxWindow;
|
|
533
549
|
private readonly maxProtected;
|
|
@@ -544,7 +560,7 @@ declare class WTinyLfuPolicy {
|
|
|
544
560
|
constructor(capacity: number, sketch: {
|
|
545
561
|
estimate(key: string): number;
|
|
546
562
|
increment(key: string): void;
|
|
547
|
-
}, windowPercent?: number, protectedPercent?: number);
|
|
563
|
+
}, windowPercent?: number, protectedPercent?: number, canEvict?: ((key: string) => boolean) | undefined);
|
|
548
564
|
get windowSize(): number;
|
|
549
565
|
get probationSize(): number;
|
|
550
566
|
get protectedSize(): number;
|
|
@@ -592,9 +608,16 @@ declare class BoundedDiskQueue {
|
|
|
592
608
|
private consecutiveFailures;
|
|
593
609
|
private circuitState;
|
|
594
610
|
private lastStateChangeMonotonic;
|
|
611
|
+
private readonly idleWaiters;
|
|
595
612
|
constructor(maxConcurrent?: number, maxPending?: number, writeTimeoutMs?: number, failureThreshold?: number, cooldownMs?: number);
|
|
613
|
+
get isSaturated(): boolean;
|
|
614
|
+
private releaseSlot;
|
|
615
|
+
/** Wait for physical work, not caller promises that may already have timed out. */
|
|
616
|
+
drain(timeoutMs?: number): Promise<boolean>;
|
|
596
617
|
schedule<T>(task: () => Promise<T>): Promise<T | null>;
|
|
597
618
|
getStats(): DiskBackpressureStats;
|
|
619
|
+
/** Resolve when every admitted physical task, including timed-out callers, settles. */
|
|
620
|
+
whenIdle(): Promise<void>;
|
|
598
621
|
reset(): void;
|
|
599
622
|
}
|
|
600
623
|
/**
|
|
@@ -638,6 +661,16 @@ declare class DiskTier {
|
|
|
638
661
|
private diskUsageBytes;
|
|
639
662
|
private usageCounted;
|
|
640
663
|
private fileCount;
|
|
664
|
+
private reservedBytes;
|
|
665
|
+
private reservedFiles;
|
|
666
|
+
private saveSequence;
|
|
667
|
+
private epoch;
|
|
668
|
+
private readonly pendingSaves;
|
|
669
|
+
private closed;
|
|
670
|
+
private readonly invalidatedKeys;
|
|
671
|
+
/** Hash buckets are bounded to 256; successful creation can be reused between spills. */
|
|
672
|
+
private readonly readyBuckets;
|
|
673
|
+
private readonly pendingBuckets;
|
|
641
674
|
/** Next bucket index (0–255) for the staggered janitor wheel. */
|
|
642
675
|
private _nextJanitorBucket;
|
|
643
676
|
private _isPruning;
|
|
@@ -657,6 +690,7 @@ declare class DiskTier {
|
|
|
657
690
|
private _stmtPruneChunk;
|
|
658
691
|
constructor(opts: DiskTierOptions);
|
|
659
692
|
private ensureDir;
|
|
693
|
+
private ensureBucket;
|
|
660
694
|
/**
|
|
661
695
|
* Initialise the SQLite metadata index. Called once after the cache directory
|
|
662
696
|
* is confirmed to exist. On any failure the instance silently falls back to
|
|
@@ -688,6 +722,10 @@ declare class DiskTier {
|
|
|
688
722
|
* 12 hex digits ≈ 6 bytes ≈ year 10889 max. Padded so length is always 77 chars.
|
|
689
723
|
*/
|
|
690
724
|
private hashToWritePath;
|
|
725
|
+
/** Fixed, path-safe suffix lets cleanup select a revision without decoding its payload. */
|
|
726
|
+
private revisionSuffix;
|
|
727
|
+
private findFilePaths;
|
|
728
|
+
private fileWrittenAt;
|
|
691
729
|
/**
|
|
692
730
|
* Find the on-disk file for a key hash, handling all filename generations:
|
|
693
731
|
* V3 (current): "{hash}_{expiresHex12}" — 77 chars
|
|
@@ -695,6 +733,7 @@ declare class DiskTier {
|
|
|
695
733
|
* Returns null when the bucket dir does not exist or the key is absent.
|
|
696
734
|
*/
|
|
697
735
|
private findFilePath;
|
|
736
|
+
private removeFile;
|
|
698
737
|
/**
|
|
699
738
|
* Recursively list all cache file paths across the 2-level sharded subdirs.
|
|
700
739
|
* Top-level entries that are not directories are skipped (e.g. stale flat
|
|
@@ -720,22 +759,48 @@ declare class DiskTier {
|
|
|
720
759
|
/**
|
|
721
760
|
* Spill an evicted L1 entry to disk.
|
|
722
761
|
*
|
|
723
|
-
* Returns
|
|
762
|
+
* Returns after the queue caller completes or times out; this is not an fsync
|
|
763
|
+
* durability guarantee. drain() separately waits for physical work. Callers
|
|
724
764
|
* that treat the spill as fire-and-forget should do:
|
|
725
765
|
* `void disk.save(key, entry)`
|
|
726
766
|
*
|
|
727
767
|
* Implementation notes:
|
|
728
|
-
* -
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
* so the Node.js event loop is never stalled waiting for disk I/O.
|
|
768
|
+
* - Serialization/compression/encryption run synchronously; CPU cost depends
|
|
769
|
+
* on payload shape and size. Index and version-cleanup work can also block.
|
|
770
|
+
* - Staging writes and rename use fs.promises. Bucket creation is coalesced,
|
|
771
|
+
* and failed staging cleanup has one owner in the physical task's finally.
|
|
733
772
|
*/
|
|
734
773
|
save(key: string, entry: DiskCacheEntry): Promise<void>;
|
|
735
774
|
/** Load a key from disk, or return null on miss/expiry/corruption. */
|
|
736
775
|
load(key: string): DiskCacheEntry | null;
|
|
737
|
-
/**
|
|
738
|
-
|
|
776
|
+
/**
|
|
777
|
+
* Async variant of load() for the SQLite-indexed path.
|
|
778
|
+
*
|
|
779
|
+
* Disk hits sit directly on the request path in front of Redis. The sync
|
|
780
|
+
* load() above blocks the event loop for readdir/stat/read/unlink; under
|
|
781
|
+
* concurrent pressure those small stalls add up to tail latency. This
|
|
782
|
+
* variant keeps the same consume-on-read and validation semantics but uses
|
|
783
|
+
* fs.promises, and only removes the indexed file instead of scanning the
|
|
784
|
+
* whole bucket. Superseded files remain unreachable through the index and
|
|
785
|
+
* are removed by the existing expiry janitor.
|
|
786
|
+
*
|
|
787
|
+
* File-only mode (no node:sqlite) falls back to the synchronous path.
|
|
788
|
+
*/
|
|
789
|
+
loadAsync(key: string): Promise<DiskCacheEntry | null>;
|
|
790
|
+
/**
|
|
791
|
+
* Delete the index row for `hash` only if it still points at `filePath`.
|
|
792
|
+
* The check and delete are synchronous, so a newer spill cannot slip between
|
|
793
|
+
* them. Returns true when this caller removed the row.
|
|
794
|
+
*/
|
|
795
|
+
private deleteIndexRowIfCurrent;
|
|
796
|
+
/** Decode and validate a raw disk payload. Callers own file cleanup. */
|
|
797
|
+
private decodeLoadedPayload;
|
|
798
|
+
/** Synchronously fence queued/running saves while leaving filesystem cleanup deferred. */
|
|
799
|
+
invalidate(key: string): void;
|
|
800
|
+
/** Cancel and remove only the observed write; newer pending or stored spills survive. */
|
|
801
|
+
deleteIfRevision(key: string, revision: string): void;
|
|
802
|
+
/** Delete all versions; deferred cleanup must not cancel a newer save. */
|
|
803
|
+
delete(key: string, invalidatedOnly?: boolean): void;
|
|
739
804
|
/** Purge all expired entries. Returns number deleted. */
|
|
740
805
|
purgeExpired(): number;
|
|
741
806
|
/**
|
|
@@ -793,6 +858,10 @@ declare class DiskTier {
|
|
|
793
858
|
};
|
|
794
859
|
/** Direct access to the bounded write queue for chaos diagnostics and canary controls. */
|
|
795
860
|
get backpressure(): BoundedDiskQueue;
|
|
861
|
+
/** Wait for admitted physical spill tasks, including work past its caller timeout. */
|
|
862
|
+
drain(timeoutMs?: number): Promise<boolean>;
|
|
863
|
+
/** Wait unboundedly for physical writes and their reservation cleanup before closing the index. */
|
|
864
|
+
whenIdle(): Promise<void>;
|
|
796
865
|
/** Whether a SQLite metadata index is active ('sqlite') or the disk is scanned directly ('file-only'). */
|
|
797
866
|
get indexMode(): 'sqlite' | 'file-only';
|
|
798
867
|
/** Release the SQLite connection (if open). Call during shutdown before deleting the cache directory. */
|
|
@@ -803,8 +872,10 @@ declare class DiskTier {
|
|
|
803
872
|
* Universal driver adapter wrapping `@redis/client` (node-redis) to satisfy TriCache's
|
|
804
873
|
* `IRedisDriver` contract without adding runtime dependencies.
|
|
805
874
|
*/
|
|
806
|
-
declare class NodeRedisAdapter implements IRedisDriver {
|
|
875
|
+
declare class NodeRedisAdapter extends EventEmitter implements IRedisDriver {
|
|
807
876
|
readonly client: any;
|
|
877
|
+
private connecting;
|
|
878
|
+
pttl?: (key: string) => Promise<number>;
|
|
808
879
|
constructor(client: any);
|
|
809
880
|
get isOpen(): boolean;
|
|
810
881
|
connect(): Promise<unknown>;
|
|
@@ -827,6 +898,11 @@ declare class NodeRedisAdapter implements IRedisDriver {
|
|
|
827
898
|
hgetall(key: string): Promise<Record<string, string>>;
|
|
828
899
|
publish(channel: string, message: string): Promise<number>;
|
|
829
900
|
subscribe(...channels: string[]): Promise<unknown>;
|
|
901
|
+
unsubscribe(...channels: string[]): Promise<unknown>;
|
|
902
|
+
xread(...args: (string | number)[]): Promise<Array<[string, Array<[string, string[]]>]> | null>;
|
|
903
|
+
xadd(...args: (string | number)[]): Promise<unknown>;
|
|
904
|
+
xrange(...args: (string | number)[]): Promise<Array<[string, string[]]>>;
|
|
905
|
+
xrevrange(...args: (string | number)[]): Promise<Array<[string, string[]]>>;
|
|
830
906
|
scanStream(options?: {
|
|
831
907
|
match?: string;
|
|
832
908
|
count?: number;
|
|
@@ -834,6 +910,7 @@ declare class NodeRedisAdapter implements IRedisDriver {
|
|
|
834
910
|
duplicate(): IRedisDriver;
|
|
835
911
|
on(event: string, listener: (...args: any[]) => void): this;
|
|
836
912
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
913
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
837
914
|
}
|
|
838
915
|
/**
|
|
839
916
|
* Creates a pluggable `IRedisDriver` adapter wrapping an existing `@redis/client` instance.
|
|
@@ -857,14 +934,18 @@ interface AutoPipelinerOptions {
|
|
|
857
934
|
/** Whether auto-pipelining is enabled. Default: true */
|
|
858
935
|
enabled?: boolean;
|
|
859
936
|
}
|
|
937
|
+
interface TimedRedisValue {
|
|
938
|
+
raw: string | Record<string, string> | null;
|
|
939
|
+
ttlMs?: number;
|
|
940
|
+
}
|
|
860
941
|
/**
|
|
861
942
|
* AutoPipeliner — Microtask-coalesced Redis request batching.
|
|
862
943
|
*
|
|
863
944
|
* Automatically combines individual Redis commands dispatched during the same synchronous
|
|
864
945
|
* tick of the Node.js event loop into a single `pipeline()` network round-trip.
|
|
865
946
|
*
|
|
866
|
-
* Uses `queueMicrotask`
|
|
867
|
-
*
|
|
947
|
+
* Uses `queueMicrotask` rather than a batching timer. Scheduling and command
|
|
948
|
+
* execution still have a cost; timed reads remain atomic within each batch.
|
|
868
949
|
*/
|
|
869
950
|
declare class AutoPipeliner {
|
|
870
951
|
private readonly client;
|
|
@@ -881,11 +962,14 @@ declare class AutoPipeliner {
|
|
|
881
962
|
pendingQueueSize: number;
|
|
882
963
|
};
|
|
883
964
|
get(key: string): Promise<string | null>;
|
|
965
|
+
read(key: string, hash?: boolean): Promise<TimedRedisValue>;
|
|
884
966
|
setex(key: string, seconds: number, value: string): Promise<void>;
|
|
967
|
+
setpx(key: string, milliseconds: number, value: string): Promise<void>;
|
|
885
968
|
del(...keys: string[]): Promise<number>;
|
|
886
969
|
private supportsPipelines;
|
|
887
970
|
private enqueue;
|
|
888
971
|
flush(): Promise<void>;
|
|
972
|
+
private dispatch;
|
|
889
973
|
}
|
|
890
974
|
|
|
891
975
|
/** Default safety ceiling for autonomous L1 memory allocations: 512 MB */
|
|
@@ -972,4 +1056,16 @@ declare function isChildTag(parentTag: string, candidateTag: string, delimiter?:
|
|
|
972
1056
|
*/
|
|
973
1057
|
declare function expandHierarchicalTags(tags: string[], delimiter?: string): string[];
|
|
974
1058
|
|
|
975
|
-
|
|
1059
|
+
/** Fail before allocating queues or starting user work. No implicit retry. */
|
|
1060
|
+
declare class CacheCapacityError extends Error {
|
|
1061
|
+
constructor(resource: string);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/** Thrown when the opt-in read gate lacks fresh invalidation consumer proof. */
|
|
1065
|
+
declare class CacheInvalidationUnavailableError extends Error {
|
|
1066
|
+
readonly reason: string;
|
|
1067
|
+
readonly detectedAt: number | null;
|
|
1068
|
+
constructor(reason: string, detectedAt: number | null);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
export { AutoPipeliner, type AutoPipelinerOptions, type AutonomousL1Options, CacheCapacityError, CacheCodec, type CacheCodecOptions, CacheEncryption, CacheHit, CacheInvalidationUnavailableError, CachePriority, CategoryLimit, CompressionAlgorithm, DEFAULT_AUTONOMOUS_L1_CEILING_BYTES, DiskCacheEntry, DiskTier, EvictionReason, type EvictionResult, ILogger, IRedisDriver, IRedisPipeline, IRemoteSnapshotAdapter, MIN_AUTONOMOUS_L1_FLOOR_BYTES, NodeRedisAdapter, type ParsedTraceParent, SigV4SnapshotAdapter, type SigV4SnapshotAdapterOptions, SmartCacheEntry, SmartMemoryCache, SnapshotRequestOptions, SnapshotTransferOptions, TinyLfuSketch, WTinyLfuCache, type WTinyLfuOptions, WTinyLfuPolicy, type WTinyLfuStats, createNodeRedisAdapter, createR2SnapshotAdapter, createS3SnapshotAdapter, createSigV4SnapshotAdapter, defaultCodec, expandHierarchicalTags, formatTraceParent, getV8HeapLimit, isChildTag, isWildcardTag, matchesTagPattern, parseTraceParent, readCgroupMemoryLimit, resolveAutonomousL1MaxBytes, resolveDefaultDiskDir };
|