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.cts
ADDED
|
@@ -0,0 +1,1071 @@
|
|
|
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-BV5T8-20.cjs';
|
|
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.cjs';
|
|
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.cjs';
|
|
4
|
+
export { B as BloomFilterStats, M as Murmur3BloomFilter, W as WasmBloomFilter, m as murmur3_32 } from './murmur3-DF8BFRnu.cjs';
|
|
5
|
+
import { EventEmitter } from 'node:events';
|
|
6
|
+
export { DashboardActionEvent, DashboardOptions, DashboardPeerInstance, StandaloneDashboardOptions, createNextDashboardHandlers, handleDashboardRequest, startDashboardServer, tricacheDashboard } from './dashboard/index.cjs';
|
|
7
|
+
import 'crypto';
|
|
8
|
+
import 'node:http';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* tricache — Zero-Dependency AWS SigV4 Snapshot Adapter
|
|
12
|
+
*
|
|
13
|
+
* Provides a lightweight (~150 LOC) AWS SigV4 request signer built purely on the
|
|
14
|
+
* standard Web Crypto API (crypto.subtle) and global fetch.
|
|
15
|
+
*
|
|
16
|
+
* Allows stateless container pods (Kubernetes, AWS ECS, GCP Cloud Run) and Edge workers
|
|
17
|
+
* to persist and hydrate L1 snapshots directly to/from AWS S3, Cloudflare R2, MinIO,
|
|
18
|
+
* or custom S3-compatible object storage WITHOUT pulling in the 30MB @aws-sdk/client-s3.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
interface SigV4SnapshotAdapterOptions extends SnapshotTransferOptions {
|
|
22
|
+
/** S3 or Cloudflare R2 bucket name */
|
|
23
|
+
bucket: string;
|
|
24
|
+
/** Object key / filename for the snapshot (e.g. 'production-l1.snap') */
|
|
25
|
+
key: string;
|
|
26
|
+
/** AWS Region. Default: 'us-east-1' (use 'auto' for Cloudflare R2) */
|
|
27
|
+
region?: string;
|
|
28
|
+
/** Custom endpoint URL (e.g. 'https://<account_id>.r2.cloudflarestorage.com' or 'http://127.0.0.1:9000') */
|
|
29
|
+
endpoint?: string;
|
|
30
|
+
/** AWS Access Key ID. Defaults to process.env.AWS_ACCESS_KEY_ID */
|
|
31
|
+
accessKeyId?: string;
|
|
32
|
+
/** AWS Secret Access Key. Defaults to process.env.AWS_SECRET_ACCESS_KEY */
|
|
33
|
+
secretAccessKey?: string;
|
|
34
|
+
/** Optional AWS Session Token (for temporary IAM/STS credentials). Defaults to process.env.AWS_SESSION_TOKEN */
|
|
35
|
+
sessionToken?: string;
|
|
36
|
+
/** Force path-style URLs (e.g. https://endpoint/bucket/key). Default: true if endpoint is specified, false for AWS S3 */
|
|
37
|
+
forcePathStyle?: boolean;
|
|
38
|
+
/** Custom fetch implementation (defaults to globalThis.fetch) */
|
|
39
|
+
fetch?: typeof globalThis.fetch;
|
|
40
|
+
}
|
|
41
|
+
declare class SigV4SnapshotAdapter implements IRemoteSnapshotAdapter {
|
|
42
|
+
private readonly bucket;
|
|
43
|
+
private readonly key;
|
|
44
|
+
private readonly region;
|
|
45
|
+
private readonly endpoint?;
|
|
46
|
+
private readonly accessKeyId;
|
|
47
|
+
private readonly secretAccessKey;
|
|
48
|
+
private readonly sessionToken?;
|
|
49
|
+
private readonly forcePathStyle;
|
|
50
|
+
private readonly fetchImpl;
|
|
51
|
+
private readonly transfer;
|
|
52
|
+
constructor(options: SigV4SnapshotAdapterOptions);
|
|
53
|
+
private _resolveTarget;
|
|
54
|
+
private _buildHeaders;
|
|
55
|
+
get(request?: SnapshotRequestOptions): Promise<Buffer | null>;
|
|
56
|
+
put(data: Buffer, request?: SnapshotRequestOptions): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates a zero-dependency AWS SigV4 snapshot adapter for AWS S3, Cloudflare R2, MinIO, or custom gateways.
|
|
60
|
+
*/
|
|
61
|
+
declare function createSigV4SnapshotAdapter(options: SigV4SnapshotAdapterOptions): IRemoteSnapshotAdapter;
|
|
62
|
+
/**
|
|
63
|
+
* Ergonomic alias for AWS S3 snapshot storage.
|
|
64
|
+
*/
|
|
65
|
+
declare function createS3SnapshotAdapter(options: SigV4SnapshotAdapterOptions): IRemoteSnapshotAdapter;
|
|
66
|
+
/**
|
|
67
|
+
* Ergonomic alias for Cloudflare R2 snapshot storage using SigV4 REST credentials.
|
|
68
|
+
*/
|
|
69
|
+
declare function createR2SnapshotAdapter(options: Omit<SigV4SnapshotAdapterOptions, 'region'> & {
|
|
70
|
+
region?: string;
|
|
71
|
+
accountId?: string;
|
|
72
|
+
}): IRemoteSnapshotAdapter;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Configuration options for the TriCache binary codec.
|
|
76
|
+
*/
|
|
77
|
+
interface CacheCodecOptions {
|
|
78
|
+
/**
|
|
79
|
+
* When true (default), objects with a toJSON() method will have toJSON() invoked.
|
|
80
|
+
* When false (msgpackr 2.1.0+), the object's own internal properties are serialized directly,
|
|
81
|
+
* avoiding accidental HTTP response projections on durable cached state.
|
|
82
|
+
*/
|
|
83
|
+
useToJSON?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Enable msgpackr record structure extension (default: true).
|
|
86
|
+
* Generates compact record definitions that yield 30-50% smaller encodings for repeated object shapes.
|
|
87
|
+
*/
|
|
88
|
+
useRecords?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Enable serialization of additional built-in types (Map, Set, TypedArray, Error, RegExp).
|
|
91
|
+
* Default: true.
|
|
92
|
+
*/
|
|
93
|
+
moreTypes?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Decode MessagePack maps as plain JavaScript objects.
|
|
96
|
+
* Default: false (preserves Map; record-encoded plain objects remain objects).
|
|
97
|
+
*/
|
|
98
|
+
mapsAsObjects?: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* CacheCodec wraps msgpackr's Packr/Unpackr to provide unified, high-performance binary
|
|
102
|
+
* serialization across L1 in-memory buffers, L1.5 disk spill, Redis, and cold-start snapshots.
|
|
103
|
+
*/
|
|
104
|
+
declare class CacheCodec {
|
|
105
|
+
private readonly packr;
|
|
106
|
+
constructor(options?: CacheCodecOptions);
|
|
107
|
+
/**
|
|
108
|
+
* Serializes a JavaScript value to a binary MessagePack Buffer.
|
|
109
|
+
*/
|
|
110
|
+
encode(data: unknown): Buffer;
|
|
111
|
+
/**
|
|
112
|
+
* Deserializes a binary MessagePack Buffer or Uint8Array back to a JavaScript value.
|
|
113
|
+
*/
|
|
114
|
+
decode<T = unknown>(data: Buffer | Uint8Array): T;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Default singleton codec configured for high-speed packing, record deduplication, and rich types.
|
|
118
|
+
*/
|
|
119
|
+
declare const defaultCodec: CacheCodec;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* SmartMemoryCache — L1 in-process cache with adaptive LFU/LRU hybrid eviction.
|
|
123
|
+
*
|
|
124
|
+
* Features:
|
|
125
|
+
* - WASM Bloom filter for O(k) guaranteed-miss detection (pure-JS fallback)
|
|
126
|
+
* - msgpackr compression for entries ≥ 512 bytes
|
|
127
|
+
* - Category-aware capacity limits (prevents any single key prefix from monopolising RAM)
|
|
128
|
+
* - Priority-weighted adaptive eviction (LFU × LRU × priority score)
|
|
129
|
+
* - Stale-While-Revalidate soft-expiry support (isStale flag on get())
|
|
130
|
+
* - L1.5 disk-spill on eviction — evicted entries are sent to DiskTier before deletion
|
|
131
|
+
* - Periodic cleanup of hard-expired entries + bloom filter rebuild
|
|
132
|
+
* - Process-level singleton via globalThis (survives Next.js hot reloads)
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
interface SmartMemoryCacheOptions {
|
|
136
|
+
maxBytes: number;
|
|
137
|
+
maxEntries: number;
|
|
138
|
+
categories: Record<string, CategoryLimit>;
|
|
139
|
+
/** Storage-key prefix to skip when matching logical category prefixes. */
|
|
140
|
+
keyPrefixLength?: number;
|
|
141
|
+
diskSpill?: (key: string, entry: SmartCacheEntry) => void | Promise<void>;
|
|
142
|
+
onEviction?: (key: string, reason: EvictionReason) => void;
|
|
143
|
+
logger: ILogger;
|
|
144
|
+
/** Fraction of maxEntries / maxBytes at which proactive eviction fires (default 0.9). */
|
|
145
|
+
evictionWatermark?: number;
|
|
146
|
+
/** Custom binary codec (defaults to defaultCodec with record structures and rich types enabled). */
|
|
147
|
+
codec?: CacheCodec;
|
|
148
|
+
/**
|
|
149
|
+
* Admission policy:
|
|
150
|
+
* - 'wtinylfu': Window TinyLFU segmented admission with mathematical scan resistance.
|
|
151
|
+
* - 'adaptive': Adaptive LFU x LRU x priority reservoir sampling.
|
|
152
|
+
* Default: 'adaptive' (unless explicitly set to 'wtinylfu')
|
|
153
|
+
*/
|
|
154
|
+
admissionPolicy?: 'wtinylfu' | 'adaptive';
|
|
155
|
+
}
|
|
156
|
+
declare class SmartMemoryCache {
|
|
157
|
+
private readonly cache;
|
|
158
|
+
private readonly opts;
|
|
159
|
+
private readonly codec;
|
|
160
|
+
private bloom;
|
|
161
|
+
/** Non-default category prefixes pre-extracted to avoid Object.keys() allocation on every call. */
|
|
162
|
+
private readonly categoryPrefixes;
|
|
163
|
+
/** Historical frequency sketch — survives eviction, closes same-priority burst-flood gap. */
|
|
164
|
+
private readonly sketch;
|
|
165
|
+
private readonly wtinyPolicy?;
|
|
166
|
+
private totalSize;
|
|
167
|
+
private categoryCount;
|
|
168
|
+
private categorySize;
|
|
169
|
+
/** Per-category key sets — enables O(catSize) Phase-1 reservoir sampling without an O(N) scan. */
|
|
170
|
+
private categoryKeys;
|
|
171
|
+
private bloomChecks;
|
|
172
|
+
private bloomFalsePos;
|
|
173
|
+
private bloomAbsentChecks;
|
|
174
|
+
private compressions;
|
|
175
|
+
private categoryHits;
|
|
176
|
+
/** Counts every _delete() call — used to trigger bloom rebuild from ALL deletion paths. */
|
|
177
|
+
private _bloomDirtyCount;
|
|
178
|
+
/**
|
|
179
|
+
* Pre-allocated eviction candidate pools — reused across every smartEvict() call to
|
|
180
|
+
* eliminate per-call heap pressure. Each slot holds a mutable {key, score} record
|
|
181
|
+
* that is overwritten in-place rather than replaced with a new object literal.
|
|
182
|
+
* Safe because JS is single-threaded: smartEvict() completes synchronously before
|
|
183
|
+
* any other code can observe the pool state.
|
|
184
|
+
*/
|
|
185
|
+
private readonly _evictPool;
|
|
186
|
+
private readonly _evictGPool;
|
|
187
|
+
constructor(opts: SmartMemoryCacheOptions, existing?: Map<string, SmartCacheEntry>);
|
|
188
|
+
private recalculateStats;
|
|
189
|
+
private getCategory;
|
|
190
|
+
private getCategoryLimit;
|
|
191
|
+
private _delete;
|
|
192
|
+
private ensureCapacity;
|
|
193
|
+
private score;
|
|
194
|
+
/**
|
|
195
|
+
* Rebuild the bloom filter when phantom bits from deleted/expired keys have
|
|
196
|
+
* saturated the filter past its ~1 % FP capacity.
|
|
197
|
+
*
|
|
198
|
+
* Trigger: (insertions − live entries) > maxCapacity
|
|
199
|
+
*
|
|
200
|
+
* Using the phantom count (insertions − cache.size) instead of raw insertions
|
|
201
|
+
* prevents an O(cache.size) rebuild from re-firing on every set() when the
|
|
202
|
+
* cache holds more entries than the filter's rated capacity — which would
|
|
203
|
+
* stall the write path entirely.
|
|
204
|
+
*
|
|
205
|
+
* After rebuild: insertions = cache.size → phantoms = 0 → no immediate re-trigger.
|
|
206
|
+
*/
|
|
207
|
+
private maybeRebuildBloom;
|
|
208
|
+
private smartEvict;
|
|
209
|
+
get(key: string): CacheHit | null;
|
|
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;
|
|
220
|
+
delete(key: string): boolean;
|
|
221
|
+
private keysMatchingPattern;
|
|
222
|
+
deletePattern(pattern: string): number;
|
|
223
|
+
/** Flush all entries, or only those whose key starts with `prefix`. */
|
|
224
|
+
clear(prefix?: string): number;
|
|
225
|
+
/**
|
|
226
|
+
* Evict entries that violate current category or global limits.
|
|
227
|
+
* Returns the number of entries evicted.
|
|
228
|
+
*/
|
|
229
|
+
rebalance(): number;
|
|
230
|
+
/**
|
|
231
|
+
* Return remaining TTL in seconds for a key in L1, or null if absent/expired.
|
|
232
|
+
* Only reflects L1 state — does not query Redis or disk.
|
|
233
|
+
*/
|
|
234
|
+
ttl(key: string): number | null;
|
|
235
|
+
/**
|
|
236
|
+
* Forcibly evict the coldest `pct` fraction of non-CRITICAL L1 entries,
|
|
237
|
+
* spilling each to L1.5 disk. Called by the OOM guard when heap pressure
|
|
238
|
+
* exceeds the configured threshold.
|
|
239
|
+
*
|
|
240
|
+
* @param pct - Fraction to evict (0–1), e.g. 0.2 = 20 %
|
|
241
|
+
* @returns Number of entries evicted
|
|
242
|
+
*/
|
|
243
|
+
evictPercentage(pct: number): number;
|
|
244
|
+
cleanup(): number;
|
|
245
|
+
/**
|
|
246
|
+
* Evict all L1 entries that were written before `cutoffMs`, at every priority.
|
|
247
|
+
*
|
|
248
|
+
* Called by the backplane staleness fence when the Pub/Sub subscriber
|
|
249
|
+
* reconnects after a disconnect gap that exceeded `backplaneMaxStalenessMs`.
|
|
250
|
+
* Entries written before the disconnect started may have been invalidated by
|
|
251
|
+
* peers while the backplane was down; evicting them forces a controlled
|
|
252
|
+
* cold-start re-fetch from L2 rather than serving silently stale data.
|
|
253
|
+
*
|
|
254
|
+
* Write-time is read from `entry.setAt` (set by `SmartMemoryCache.set()` since v0.7.0).
|
|
255
|
+
* Older snapshot entries without `setAt` fall back to approximating via `expiresAt - ttlMs`;
|
|
256
|
+
* entries with neither field are treated as potentially stale and evicted conservatively.
|
|
257
|
+
*
|
|
258
|
+
* @param cutoffMs - Unix timestamp in milliseconds; entries written before
|
|
259
|
+
* this time are evicted.
|
|
260
|
+
* @returns Number of entries evicted.
|
|
261
|
+
*/
|
|
262
|
+
evictSetBefore(cutoffMs: number): number;
|
|
263
|
+
/**
|
|
264
|
+
* Delete a key only if its write timestamp (`setAt`) is <= `cutoffMs`.
|
|
265
|
+
* This is a time-based eviction policy; use deleteIfRevision for write identity.
|
|
266
|
+
*/
|
|
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;
|
|
270
|
+
exportEntries(forbiddenPrefixes: readonly string[]): Array<{
|
|
271
|
+
key: string;
|
|
272
|
+
entry: SmartCacheEntry;
|
|
273
|
+
}>;
|
|
274
|
+
importEntries(entries: Array<{
|
|
275
|
+
key: string;
|
|
276
|
+
entry: SmartCacheEntry;
|
|
277
|
+
}>, forbiddenPrefixes: readonly string[]): number;
|
|
278
|
+
/**
|
|
279
|
+
* Lazily yields every [key, entry] pair whose TTL has not yet expired.
|
|
280
|
+
* Expired entries that are still in the Map (awaiting background cleanup)
|
|
281
|
+
* are silently skipped.
|
|
282
|
+
*/
|
|
283
|
+
liveEntries(): Generator<[string, SmartCacheEntry]>;
|
|
284
|
+
/**
|
|
285
|
+
* Non-generator bulk scan over all live entries.
|
|
286
|
+
*
|
|
287
|
+
* Faster than the generator-based iterators for bulk operations because:
|
|
288
|
+
* - No generator state-machine overhead (no yield/resume suspend points).
|
|
289
|
+
* - No per-entry tuple allocation (compare `liveEntries()` which yields `[key, entry]`).
|
|
290
|
+
* - The same Map call-site is used by a single plain `for` loop instead of being
|
|
291
|
+
* shared across three competing generator functions, giving V8's IC a cleaner
|
|
292
|
+
* monomorphic profile for this path.
|
|
293
|
+
*
|
|
294
|
+
* The callback receives the raw (namespaced) key and a `prefixLen` offset so the
|
|
295
|
+
* caller can call `key.slice(prefixLen)` only when it actually needs the stripped
|
|
296
|
+
* key, avoiding the allocation entirely for callers that don't.
|
|
297
|
+
*
|
|
298
|
+
* @param fn Called once per live entry.
|
|
299
|
+
* @param prefixLen Number of bytes to skip to reach the un-namespaced portion of the key.
|
|
300
|
+
* Pass 0 when no namespace is configured.
|
|
301
|
+
*/
|
|
302
|
+
scan(fn: (key: string, entry: SmartCacheEntry, prefixLen: number) => void, prefixLen: number): void;
|
|
303
|
+
/**
|
|
304
|
+
* Yields only the keys of live entries — no intermediate tuple allocation.
|
|
305
|
+
* Use this instead of liveEntries() when you only need keys.
|
|
306
|
+
*/
|
|
307
|
+
liveKeys(): Generator<string>;
|
|
308
|
+
/**
|
|
309
|
+
* Yields only the resolved values of live entries.
|
|
310
|
+
* Iterates Map.values() so the key is never loaded into the yielded path.
|
|
311
|
+
* Returns the deserialized value — identical semantics to get() but without bloom/hit tracking.
|
|
312
|
+
*/
|
|
313
|
+
liveValues(): Generator<unknown>;
|
|
314
|
+
/**
|
|
315
|
+
* Returns the deserialized value for an entry, unpacking from the msgpackr buffer
|
|
316
|
+
* if the live object was not cached (large-entry optimisation or disk-restored entry).
|
|
317
|
+
*/
|
|
318
|
+
resolveValue(entry: SmartCacheEntry): unknown;
|
|
319
|
+
get size(): number;
|
|
320
|
+
get memoryUsage(): number;
|
|
321
|
+
getStats(): {
|
|
322
|
+
entries: number;
|
|
323
|
+
sizeBytes: number;
|
|
324
|
+
sizeKB: number;
|
|
325
|
+
categories: Record<string, {
|
|
326
|
+
entries: number;
|
|
327
|
+
hits: number;
|
|
328
|
+
}>;
|
|
329
|
+
bloom: {
|
|
330
|
+
checks: number;
|
|
331
|
+
falsePositives: number;
|
|
332
|
+
absentChecks: number;
|
|
333
|
+
};
|
|
334
|
+
compression: {
|
|
335
|
+
compressed: number;
|
|
336
|
+
uncompressed: number;
|
|
337
|
+
bytesSaved: number;
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Return the raw cache entry for a key, or `undefined` if absent/expired.
|
|
342
|
+
* Does NOT count as a hit or perform SWR logic.
|
|
343
|
+
*/
|
|
344
|
+
getEntry(key: string): SmartCacheEntry | undefined;
|
|
345
|
+
/**
|
|
346
|
+
* Return true if the key exists in L1 and has not expired.
|
|
347
|
+
* Uses the bloom filter as a fast negative check.
|
|
348
|
+
*/
|
|
349
|
+
has(key: string): boolean;
|
|
350
|
+
/**
|
|
351
|
+
* Extend the TTL of an existing key. Returns `false` if the key is absent or expired.
|
|
352
|
+
* @param newTtlMs - New TTL from now, in milliseconds.
|
|
353
|
+
*/
|
|
354
|
+
touch(key: string, newTtlMs: number): boolean;
|
|
355
|
+
/**
|
|
356
|
+
* Add additional milliseconds to a key's existing expiry (for stale-if-error).
|
|
357
|
+
* Returns `false` if the key is absent or already expired.
|
|
358
|
+
*/
|
|
359
|
+
bumpExpiry(key: string, additionalMs: number, maximumExpiry?: number): boolean;
|
|
360
|
+
bloomMightContain(key: string): boolean;
|
|
361
|
+
bloomStats(): {
|
|
362
|
+
bitsSet: number;
|
|
363
|
+
fillFactor: number;
|
|
364
|
+
} | {
|
|
365
|
+
bitsSet: number;
|
|
366
|
+
fillFactor: number;
|
|
367
|
+
};
|
|
368
|
+
/**
|
|
369
|
+
* Return the top-N live L1 keys by historical access frequency (Count-Min Sketch estimate).
|
|
370
|
+
* Includes evicted-then-readmitted keys whose sketch frequency exceeds their current hit count.
|
|
371
|
+
* Useful for diagnosing which keys are driving cache pressure.
|
|
372
|
+
*
|
|
373
|
+
* @param n - Maximum number of entries to return. Default: 10.
|
|
374
|
+
*/
|
|
375
|
+
hotKeys(n: number): Array<{
|
|
376
|
+
key: string;
|
|
377
|
+
hits: number;
|
|
378
|
+
sizeBytes: number;
|
|
379
|
+
}>;
|
|
380
|
+
/**
|
|
381
|
+
* Return real-time metrics and telemetry for the Window TinyLFU admission policy.
|
|
382
|
+
* Returns `undefined` when running under default adaptive eviction.
|
|
383
|
+
*/
|
|
384
|
+
getWTinyLfuStats(): WTinyLfuStats$1 | undefined;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* tricache — Native Window TinyLFU (W-TinyLFU) Admission Engine
|
|
389
|
+
*
|
|
390
|
+
* Implements the state-of-the-art W-TinyLFU cache architecture popularized by Caffeine:
|
|
391
|
+
*
|
|
392
|
+
* [Incoming Entry]
|
|
393
|
+
* │
|
|
394
|
+
* ▼
|
|
395
|
+
* ┌───────────────────────────┐
|
|
396
|
+
* │ Window Cache (LRU) │ ~1% of Total Capacity
|
|
397
|
+
* │ (Absorbs Burst Recency) │
|
|
398
|
+
* └─────────────┬─────────────┘
|
|
399
|
+
* │ Evicted from Window
|
|
400
|
+
* ▼
|
|
401
|
+
* [TinyLFU Admission]
|
|
402
|
+
* Freq(Candidate) > Freq(Victim)?
|
|
403
|
+
* │
|
|
404
|
+
* ┌───────────────┴───────────────┐
|
|
405
|
+
* │ YES │ NO
|
|
406
|
+
* ▼ ▼
|
|
407
|
+
* ┌──────────────────────┐ [Drop Candidate]
|
|
408
|
+
* │ Probationary SLRU │ ~20% of Main
|
|
409
|
+
* └──────────┬───────────┘
|
|
410
|
+
* │ On 2nd Hit
|
|
411
|
+
* ▼
|
|
412
|
+
* ┌──────────────────────┐
|
|
413
|
+
* │ Protected SLRU │ ~80% of Main
|
|
414
|
+
* └──────────────────────┘
|
|
415
|
+
*
|
|
416
|
+
* Characteristics:
|
|
417
|
+
* - Pure TypeScript with zero external dependencies
|
|
418
|
+
* - Mathematical scan resistance: large sequential scans never pollute the main cache
|
|
419
|
+
* - Burst recency absorption: short-lived temporal spikes hit in the Window without eviction churn
|
|
420
|
+
* - Near-optimal theoretical hit ratios on Zipfian distributions
|
|
421
|
+
*/
|
|
422
|
+
interface WTinyLfuOptions {
|
|
423
|
+
/** Total maximum number of entries across all segments (Window + Probation + Protected). Default: 10,000 */
|
|
424
|
+
capacity: number;
|
|
425
|
+
/** Fraction of total capacity dedicated to Window Cache for burst recency absorption. Default: 0.01 (1%) */
|
|
426
|
+
windowPercent?: number;
|
|
427
|
+
/** Fraction of main SLRU space allocated to Protected segment. Default: 0.80 (80%) */
|
|
428
|
+
protectedPercent?: number;
|
|
429
|
+
/** Width of Count-Min Sketch rows (power of 2). Default: 1024 */
|
|
430
|
+
sketchWidth?: number;
|
|
431
|
+
}
|
|
432
|
+
interface WTinyLfuStats {
|
|
433
|
+
capacity: number;
|
|
434
|
+
size: number;
|
|
435
|
+
windowSize: number;
|
|
436
|
+
probationSize: number;
|
|
437
|
+
protectedSize: number;
|
|
438
|
+
hits: number;
|
|
439
|
+
misses: number;
|
|
440
|
+
hitRate: number;
|
|
441
|
+
admissions: number;
|
|
442
|
+
rejections: number;
|
|
443
|
+
demotions: number;
|
|
444
|
+
promotions: number;
|
|
445
|
+
}
|
|
446
|
+
interface EvictionResult<K, V> {
|
|
447
|
+
evicted?: {
|
|
448
|
+
key: K;
|
|
449
|
+
value: V;
|
|
450
|
+
segment: 'window' | 'probation' | 'protected';
|
|
451
|
+
};
|
|
452
|
+
rejected?: {
|
|
453
|
+
key: K;
|
|
454
|
+
value: V;
|
|
455
|
+
segment: 'window';
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* 4-row Count-Min Sketch for TinyLFU frequency estimation.
|
|
460
|
+
* Uses Murmur3-style bit-mixes of FNV-1a digests with periodic halving decay.
|
|
461
|
+
*/
|
|
462
|
+
declare class TinyLfuSketch {
|
|
463
|
+
private readonly rows;
|
|
464
|
+
private readonly width;
|
|
465
|
+
private readonly mask;
|
|
466
|
+
private readonly table;
|
|
467
|
+
private insertions;
|
|
468
|
+
private readonly decayThreshold;
|
|
469
|
+
constructor(width?: number, decayThreshold?: number);
|
|
470
|
+
private hash;
|
|
471
|
+
increment(key: string): void;
|
|
472
|
+
estimate(key: string): number;
|
|
473
|
+
decay(): void;
|
|
474
|
+
clear(): void;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Window TinyLFU (W-TinyLFU) Segmented Cache.
|
|
478
|
+
*/
|
|
479
|
+
declare class WTinyLfuCache<K = string, V = unknown> {
|
|
480
|
+
private readonly maxTotal;
|
|
481
|
+
private readonly maxWindow;
|
|
482
|
+
private readonly maxProtected;
|
|
483
|
+
private readonly maxProbation;
|
|
484
|
+
private readonly window;
|
|
485
|
+
private readonly probation;
|
|
486
|
+
private readonly protected_;
|
|
487
|
+
private readonly sketch;
|
|
488
|
+
private hitCount;
|
|
489
|
+
private missCount;
|
|
490
|
+
private admissionCount;
|
|
491
|
+
private rejectionCount;
|
|
492
|
+
private promotionCount;
|
|
493
|
+
private demotionCount;
|
|
494
|
+
constructor(options: WTinyLfuOptions);
|
|
495
|
+
get capacity(): number;
|
|
496
|
+
get size(): number;
|
|
497
|
+
private keyToString;
|
|
498
|
+
/**
|
|
499
|
+
* Retrieves an entry and performs W-TinyLFU access promotion.
|
|
500
|
+
*/
|
|
501
|
+
get(key: K): V | undefined;
|
|
502
|
+
/**
|
|
503
|
+
* Returns true if key exists in any segment without updating access frequency.
|
|
504
|
+
*/
|
|
505
|
+
has(key: K): boolean;
|
|
506
|
+
/**
|
|
507
|
+
* Puts an entry into the cache using W-TinyLFU admission policies.
|
|
508
|
+
*/
|
|
509
|
+
set(key: K, value: V): EvictionResult<K, V>;
|
|
510
|
+
/**
|
|
511
|
+
* Removes a key from whichever segment it resides in.
|
|
512
|
+
*/
|
|
513
|
+
delete(key: K): boolean;
|
|
514
|
+
/**
|
|
515
|
+
* Resets all segments, sketch, and metrics.
|
|
516
|
+
*/
|
|
517
|
+
clear(): void;
|
|
518
|
+
/**
|
|
519
|
+
* Returns current telemetry and hit-ratio stats.
|
|
520
|
+
*/
|
|
521
|
+
stats(): WTinyLfuStats;
|
|
522
|
+
getStats(): WTinyLfuStats;
|
|
523
|
+
/**
|
|
524
|
+
* Returns an iterator of all keys currently in the cache.
|
|
525
|
+
*/
|
|
526
|
+
keys(): IterableIterator<K>;
|
|
527
|
+
/**
|
|
528
|
+
* Returns an iterator of all entries currently in the cache.
|
|
529
|
+
*/
|
|
530
|
+
entries(): IterableIterator<[K, V]>;
|
|
531
|
+
/**
|
|
532
|
+
* Returns segment membership for a key ('window', 'probation', 'protected', or null).
|
|
533
|
+
*/
|
|
534
|
+
getSegment(key: K): 'window' | 'probation' | 'protected' | null;
|
|
535
|
+
}
|
|
536
|
+
interface WTinyLfuAdmissionDecision {
|
|
537
|
+
admit: boolean;
|
|
538
|
+
evictKey?: string;
|
|
539
|
+
candidateKey?: string;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Lightweight W-TinyLFU policy controller for existing tiered caches like SmartMemoryCache.
|
|
543
|
+
*/
|
|
544
|
+
declare class WTinyLfuPolicy {
|
|
545
|
+
private readonly sketch;
|
|
546
|
+
private readonly canEvict?;
|
|
547
|
+
private readonly maxTotal;
|
|
548
|
+
private readonly maxWindow;
|
|
549
|
+
private readonly maxProtected;
|
|
550
|
+
private readonly maxProbation;
|
|
551
|
+
private readonly window;
|
|
552
|
+
private readonly probation;
|
|
553
|
+
private readonly protected_;
|
|
554
|
+
private hitCount;
|
|
555
|
+
private missCount;
|
|
556
|
+
private admissionCount;
|
|
557
|
+
private rejectionCount;
|
|
558
|
+
private promotionCount;
|
|
559
|
+
private demotionCount;
|
|
560
|
+
constructor(capacity: number, sketch: {
|
|
561
|
+
estimate(key: string): number;
|
|
562
|
+
increment(key: string): void;
|
|
563
|
+
}, windowPercent?: number, protectedPercent?: number, canEvict?: ((key: string) => boolean) | undefined);
|
|
564
|
+
get windowSize(): number;
|
|
565
|
+
get probationSize(): number;
|
|
566
|
+
get protectedSize(): number;
|
|
567
|
+
onAccess(key: string): void;
|
|
568
|
+
onSet(key: string, isUpdate: boolean): WTinyLfuAdmissionDecision;
|
|
569
|
+
onDelete(key: string): void;
|
|
570
|
+
clear(): void;
|
|
571
|
+
getStats(): WTinyLfuStats;
|
|
572
|
+
getSegment(key: string): 'window' | 'probation' | 'protected' | null;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* DiskTier — L1.5 NVMe-fast overflow cache between L1 RAM and L2 Redis/DB.
|
|
577
|
+
*
|
|
578
|
+
* When L1 evicts an entry it is spilled here instead of being discarded.
|
|
579
|
+
* On a subsequent L1 miss the entry is promoted back (2–100 µs disk read
|
|
580
|
+
* vs 10–100 ms DB round-trip).
|
|
581
|
+
*
|
|
582
|
+
* Storage:
|
|
583
|
+
* - Directory: configurable (default os.tmpdir()/tricache-disk)
|
|
584
|
+
* - Filename: SHA-256(key) hex — bounded, URL-safe, no key injection
|
|
585
|
+
* - Format: msgpack({ version, key, entry, writtenAt })
|
|
586
|
+
* - Mode: 0o600 — owner read/write only
|
|
587
|
+
*
|
|
588
|
+
* Encryption: same AES-256-GCM as L2 when CacheEncryption is configured.
|
|
589
|
+
*/
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* BoundedDiskQueue — Concurrency-controlled write spooler with circuit breaking.
|
|
593
|
+
*
|
|
594
|
+
* Prevents libuv threadpool (UV_THREADPOOL_SIZE=4) starvation during cloud NVMe / EBS
|
|
595
|
+
* latency spikes (e.g. 450ms multi-tenant throttle) by limiting active async fs operations,
|
|
596
|
+
* bounding in-memory pending queues, and fast-shedding spills via a 3-state circuit breaker
|
|
597
|
+
* (CLOSED -> OPEN -> HALF-OPEN canary).
|
|
598
|
+
*/
|
|
599
|
+
declare class BoundedDiskQueue {
|
|
600
|
+
private readonly maxConcurrent;
|
|
601
|
+
private readonly maxPending;
|
|
602
|
+
private readonly writeTimeoutMs;
|
|
603
|
+
private readonly failureThreshold;
|
|
604
|
+
private readonly cooldownMs;
|
|
605
|
+
private active;
|
|
606
|
+
private queue;
|
|
607
|
+
private spillsDropped;
|
|
608
|
+
private consecutiveFailures;
|
|
609
|
+
private circuitState;
|
|
610
|
+
private lastStateChangeMonotonic;
|
|
611
|
+
private readonly idleWaiters;
|
|
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>;
|
|
617
|
+
schedule<T>(task: () => Promise<T>): Promise<T | null>;
|
|
618
|
+
getStats(): DiskBackpressureStats;
|
|
619
|
+
/** Resolve when every admitted physical task, including timed-out callers, settles. */
|
|
620
|
+
whenIdle(): Promise<void>;
|
|
621
|
+
reset(): void;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Resolves the default directory for DiskTier storage.
|
|
625
|
+
*
|
|
626
|
+
* In Linux container environments, checks if `/dev/shm` (POSIX shared memory tmpfs)
|
|
627
|
+
* is writable and has adequate capacity (total >= 256MB AND free >= 128MB).
|
|
628
|
+
* When valid, targets `/dev/shm` to provide an off-heap, zero-GC RAM extension
|
|
629
|
+
* that runs at memory speeds (~20µs) and burns zero cloud/EBS IOPS.
|
|
630
|
+
* If capacity or free space is insufficient, or on non-Linux platforms,
|
|
631
|
+
* gracefully falls back to `os.tmpdir()`.
|
|
632
|
+
*/
|
|
633
|
+
declare function resolveDefaultDiskDir(namespace?: string, logger?: ILogger): {
|
|
634
|
+
dir: string;
|
|
635
|
+
isShm: boolean;
|
|
636
|
+
};
|
|
637
|
+
interface DiskTierOptions {
|
|
638
|
+
dir: string;
|
|
639
|
+
maxBytes: number;
|
|
640
|
+
entryMaxBytes: number;
|
|
641
|
+
forbiddenPrefixes?: readonly string[];
|
|
642
|
+
/** Mode-aware encryption instance. When set, disk files are encrypted with the
|
|
643
|
+
* same algorithm as L2/Redis (aes-256-gcm, aes-128-gcm, aes-128-ctr, or xor).
|
|
644
|
+
* When null, files are written unencrypted. Pass `cache.encryption` here. */
|
|
645
|
+
encryption?: CacheEncryption | null;
|
|
646
|
+
compression?: CompressionAlgorithm;
|
|
647
|
+
compressionThresholdBytes?: number;
|
|
648
|
+
logger: ILogger;
|
|
649
|
+
codec?: CacheCodec;
|
|
650
|
+
diskMaxConcurrentWrites?: number;
|
|
651
|
+
diskMaxPendingWrites?: number;
|
|
652
|
+
diskWriteTimeoutMs?: number;
|
|
653
|
+
diskCircuitBreakerThreshold?: number;
|
|
654
|
+
diskCircuitBreakerCooldownMs?: number;
|
|
655
|
+
}
|
|
656
|
+
declare class DiskTier {
|
|
657
|
+
private readonly opts;
|
|
658
|
+
private readonly codec;
|
|
659
|
+
private readonly diskQueue;
|
|
660
|
+
private dirReady;
|
|
661
|
+
private diskUsageBytes;
|
|
662
|
+
private usageCounted;
|
|
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;
|
|
674
|
+
/** Next bucket index (0–255) for the staggered janitor wheel. */
|
|
675
|
+
private _nextJanitorBucket;
|
|
676
|
+
private _isPruning;
|
|
677
|
+
private _pruneRounds;
|
|
678
|
+
private _entriesPruned;
|
|
679
|
+
private _spillsShedTotal;
|
|
680
|
+
private _hostVolumeLowSpace;
|
|
681
|
+
private _hostVolumeLowSpacePauses;
|
|
682
|
+
private _writeCounter;
|
|
683
|
+
private _db;
|
|
684
|
+
private _stmtInsert;
|
|
685
|
+
private _stmtSelect;
|
|
686
|
+
private _stmtDelete;
|
|
687
|
+
private _stmtExpire;
|
|
688
|
+
private _stmtDelExp;
|
|
689
|
+
private _stmtStats;
|
|
690
|
+
private _stmtPruneChunk;
|
|
691
|
+
constructor(opts: DiskTierOptions);
|
|
692
|
+
private ensureDir;
|
|
693
|
+
private ensureBucket;
|
|
694
|
+
/**
|
|
695
|
+
* Initialise the SQLite metadata index. Called once after the cache directory
|
|
696
|
+
* is confirmed to exist. On any failure the instance silently falls back to
|
|
697
|
+
* file-only mode — all public methods handle `this._db === null`.
|
|
698
|
+
*
|
|
699
|
+
* Schema:
|
|
700
|
+
* meta(key_hash TEXT PK, file_path TEXT, expires_at INT, size INT)
|
|
701
|
+
* idx_expires on (expires_at) — makes WHERE expires_at <= ? O(log n).
|
|
702
|
+
*
|
|
703
|
+
* WAL + synchronous=NORMAL: durable enough for a cache (a crash loses at
|
|
704
|
+
* most one WAL frame — acceptable data loss for an L1.5 spill store).
|
|
705
|
+
*/
|
|
706
|
+
private _initSqlite;
|
|
707
|
+
private ensureUsageCounted;
|
|
708
|
+
/**
|
|
709
|
+
* SHA-256 hex digest of a key (pure CPU, no I/O).
|
|
710
|
+
* Kept separate from path construction so callers can find files by prefix
|
|
711
|
+
* without knowing which filename generation was used when the file was written.
|
|
712
|
+
*/
|
|
713
|
+
private keyToHash;
|
|
714
|
+
/**
|
|
715
|
+
* Build the write path for a NEW file (V3 generation).
|
|
716
|
+
* Encoding expiresAt in the filename lets purgeNextBucket() skip live entries
|
|
717
|
+
* with zero file I/O — after readdirSync() it only needs a string parse.
|
|
718
|
+
*
|
|
719
|
+
* {dir}/{hash[0..1]}/{hash}_{expiresAt-hex-12}
|
|
720
|
+
* e.g. {dir}/e3/e3b0c442…abcd_018f7c3b5a00
|
|
721
|
+
*
|
|
722
|
+
* 12 hex digits ≈ 6 bytes ≈ year 10889 max. Padded so length is always 77 chars.
|
|
723
|
+
*/
|
|
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;
|
|
729
|
+
/**
|
|
730
|
+
* Find the on-disk file for a key hash, handling all filename generations:
|
|
731
|
+
* V3 (current): "{hash}_{expiresHex12}" — 77 chars
|
|
732
|
+
* V1/V2 (older): "{hash}" — 64 chars, no suffix
|
|
733
|
+
* Returns null when the bucket dir does not exist or the key is absent.
|
|
734
|
+
*/
|
|
735
|
+
private findFilePath;
|
|
736
|
+
private removeFile;
|
|
737
|
+
/**
|
|
738
|
+
* Recursively list all cache file paths across the 2-level sharded subdirs.
|
|
739
|
+
* Top-level entries that are not directories are skipped (e.g. stale flat
|
|
740
|
+
* files written by older versions).
|
|
741
|
+
*/
|
|
742
|
+
private walkCacheFiles;
|
|
743
|
+
private isForbidden;
|
|
744
|
+
private encrypt;
|
|
745
|
+
private decrypt;
|
|
746
|
+
/**
|
|
747
|
+
* V2 encryption — returns the mode-aware encrypted payload (no magic prefix; the
|
|
748
|
+
* magic + plaintext expiresAt live in the outer 16-byte header written by `save`).
|
|
749
|
+
* Returns the buffer unchanged when no encryption instance is configured.
|
|
750
|
+
*/
|
|
751
|
+
private encryptV2;
|
|
752
|
+
/**
|
|
753
|
+
* V2 decryption — inner payload after stripping the 16-byte header.
|
|
754
|
+
* When an encryption instance is configured the format is the mode-aware
|
|
755
|
+
* CacheEncryption blob (IV|TAG|CT for GCM, IV|CT for CTR, key⊕data for XOR);
|
|
756
|
+
* without one the payload is raw msgpack.
|
|
757
|
+
*/
|
|
758
|
+
private decryptV2;
|
|
759
|
+
/**
|
|
760
|
+
* Spill an evicted L1 entry to disk.
|
|
761
|
+
*
|
|
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
|
|
764
|
+
* that treat the spill as fire-and-forget should do:
|
|
765
|
+
* `void disk.save(key, entry)`
|
|
766
|
+
*
|
|
767
|
+
* Implementation notes:
|
|
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.
|
|
772
|
+
*/
|
|
773
|
+
save(key: string, entry: DiskCacheEntry): Promise<void>;
|
|
774
|
+
/** Load a key from disk, or return null on miss/expiry/corruption. */
|
|
775
|
+
load(key: string): DiskCacheEntry | null;
|
|
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;
|
|
804
|
+
/** Purge all expired entries. Returns number deleted. */
|
|
805
|
+
purgeExpired(): number;
|
|
806
|
+
/**
|
|
807
|
+
* Purge expired entries. Two modes depending on availability of SQLite:
|
|
808
|
+
*
|
|
809
|
+
* SQLite mode (Node 24 / Node 22 + --experimental-sqlite):
|
|
810
|
+
* One indexed query (`WHERE expires_at <= now`) replaces the entire bucket
|
|
811
|
+
* wheel. All expired entries are found and deleted in a single pass — the
|
|
812
|
+
* 128-minute stagger is no longer necessary. `_nextJanitorBucket` is still
|
|
813
|
+
* incremented so tests that inspect the counter continue to work.
|
|
814
|
+
*
|
|
815
|
+
* File-only fallback:
|
|
816
|
+
* Original staggered bucket wheel — purges exactly one of 256 subdirectory
|
|
817
|
+
* buckets per call, spreading the O(fileCount) work across 256 ticks.
|
|
818
|
+
*
|
|
819
|
+
* Returns the number of entries deleted in this tick.
|
|
820
|
+
*/
|
|
821
|
+
purgeNextBucket(): number;
|
|
822
|
+
/** Delete every file in the disk cache. Returns the count deleted. */
|
|
823
|
+
clear(): number;
|
|
824
|
+
/**
|
|
825
|
+
* Proactively checks host volume free space via statfsSync.
|
|
826
|
+
* If free space on the volume drops below 10%, pauses spills to prevent
|
|
827
|
+
* Kubernetes pod eviction (DiskPressure / EphemeralStorageExceeded).
|
|
828
|
+
*/
|
|
829
|
+
checkHostVolumeHealth(): boolean;
|
|
830
|
+
/**
|
|
831
|
+
* Non-blocking chunked pruning:
|
|
832
|
+
* Evicts oldest entries in 500-entry chunks down to 60% watermark,
|
|
833
|
+
* yielding to the event loop via setImmediate between chunks.
|
|
834
|
+
*/
|
|
835
|
+
triggerChunkedPrune(): Promise<number>;
|
|
836
|
+
get isPruning(): boolean;
|
|
837
|
+
get hostVolumeLowSpace(): boolean;
|
|
838
|
+
get spillsShedTotal(): number;
|
|
839
|
+
getPruningStats(): {
|
|
840
|
+
active: boolean;
|
|
841
|
+
pruneRounds: number;
|
|
842
|
+
entriesPruned: number;
|
|
843
|
+
spillsShedTotal: number;
|
|
844
|
+
hostVolumeLowSpacePauses: number;
|
|
845
|
+
};
|
|
846
|
+
get stats(): {
|
|
847
|
+
files: number;
|
|
848
|
+
sizeKB: number;
|
|
849
|
+
maxKB: number;
|
|
850
|
+
backpressure?: DiskBackpressureStats;
|
|
851
|
+
pruning?: {
|
|
852
|
+
active: boolean;
|
|
853
|
+
pruneRounds: number;
|
|
854
|
+
entriesPruned: number;
|
|
855
|
+
spillsShedTotal: number;
|
|
856
|
+
hostVolumeLowSpacePauses: number;
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
/** Direct access to the bounded write queue for chaos diagnostics and canary controls. */
|
|
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>;
|
|
865
|
+
/** Whether a SQLite metadata index is active ('sqlite') or the disk is scanned directly ('file-only'). */
|
|
866
|
+
get indexMode(): 'sqlite' | 'file-only';
|
|
867
|
+
/** Release the SQLite connection (if open). Call during shutdown before deleting the cache directory. */
|
|
868
|
+
close(): void;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Universal driver adapter wrapping `@redis/client` (node-redis) to satisfy TriCache's
|
|
873
|
+
* `IRedisDriver` contract without adding runtime dependencies.
|
|
874
|
+
*/
|
|
875
|
+
declare class NodeRedisAdapter extends EventEmitter implements IRedisDriver {
|
|
876
|
+
readonly client: any;
|
|
877
|
+
private connecting;
|
|
878
|
+
pttl?: (key: string) => Promise<number>;
|
|
879
|
+
constructor(client: any);
|
|
880
|
+
get isOpen(): boolean;
|
|
881
|
+
connect(): Promise<unknown>;
|
|
882
|
+
disconnect(): Promise<void>;
|
|
883
|
+
quit(): Promise<void>;
|
|
884
|
+
get(key: string): Promise<string | null>;
|
|
885
|
+
set(key: string, value: string, ...args: (string | number)[]): Promise<unknown>;
|
|
886
|
+
setex(key: string, seconds: number, value: string): Promise<unknown>;
|
|
887
|
+
del(...keys: string[]): Promise<number>;
|
|
888
|
+
ping(): Promise<string>;
|
|
889
|
+
expire(key: string, seconds: number): Promise<number | boolean>;
|
|
890
|
+
incr(key: string): Promise<number>;
|
|
891
|
+
eval(script: string, numkeys: number, ...args: (string | number)[]): Promise<unknown>;
|
|
892
|
+
multi(): IRedisPipeline;
|
|
893
|
+
pipeline(): IRedisPipeline;
|
|
894
|
+
smembers(key: string): Promise<string[]>;
|
|
895
|
+
sadd(key: string, ...members: string[]): Promise<number>;
|
|
896
|
+
mget(keys: string[]): Promise<(string | null)[]>;
|
|
897
|
+
hset(key: string, value: Record<string, string>): Promise<unknown>;
|
|
898
|
+
hgetall(key: string): Promise<Record<string, string>>;
|
|
899
|
+
publish(channel: string, message: string): Promise<number>;
|
|
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[]]>>;
|
|
906
|
+
scanStream(options?: {
|
|
907
|
+
match?: string;
|
|
908
|
+
count?: number;
|
|
909
|
+
}): EventEmitter;
|
|
910
|
+
duplicate(): IRedisDriver;
|
|
911
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
912
|
+
once(event: string, listener: (...args: any[]) => void): this;
|
|
913
|
+
removeListener(event: string, listener: (...args: any[]) => void): this;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Creates a pluggable `IRedisDriver` adapter wrapping an existing `@redis/client` instance.
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* import { createClient } from 'redis';
|
|
920
|
+
* import { CacheService, createNodeRedisAdapter } from 'tricache';
|
|
921
|
+
*
|
|
922
|
+
* const client = createClient({ url: 'redis://localhost:6379' });
|
|
923
|
+
* await client.connect();
|
|
924
|
+
*
|
|
925
|
+
* const cache = CacheService.create({
|
|
926
|
+
* redisClient: createNodeRedisAdapter(client),
|
|
927
|
+
* });
|
|
928
|
+
*/
|
|
929
|
+
declare function createNodeRedisAdapter(client: any): IRedisDriver;
|
|
930
|
+
|
|
931
|
+
interface AutoPipelinerOptions {
|
|
932
|
+
/** Maximum number of operations to coalesce before forcing an immediate pipeline dispatch. Default: 100 */
|
|
933
|
+
maxBatchSize?: number;
|
|
934
|
+
/** Whether auto-pipelining is enabled. Default: true */
|
|
935
|
+
enabled?: boolean;
|
|
936
|
+
}
|
|
937
|
+
interface TimedRedisValue {
|
|
938
|
+
raw: string | Record<string, string> | null;
|
|
939
|
+
ttlMs?: number;
|
|
940
|
+
}
|
|
941
|
+
/**
|
|
942
|
+
* AutoPipeliner — Microtask-coalesced Redis request batching.
|
|
943
|
+
*
|
|
944
|
+
* Automatically combines individual Redis commands dispatched during the same synchronous
|
|
945
|
+
* tick of the Node.js event loop into a single `pipeline()` network round-trip.
|
|
946
|
+
*
|
|
947
|
+
* Uses `queueMicrotask` rather than a batching timer. Scheduling and command
|
|
948
|
+
* execution still have a cost; timed reads remain atomic within each batch.
|
|
949
|
+
*/
|
|
950
|
+
declare class AutoPipeliner {
|
|
951
|
+
private readonly client;
|
|
952
|
+
readonly maxBatchSize: number;
|
|
953
|
+
enabled: boolean;
|
|
954
|
+
private queue;
|
|
955
|
+
private scheduled;
|
|
956
|
+
private inFlight;
|
|
957
|
+
private statsInternal;
|
|
958
|
+
constructor(client: IRedisDriver | any, options?: AutoPipelinerOptions);
|
|
959
|
+
get stats(): {
|
|
960
|
+
batchesDispatched: number;
|
|
961
|
+
operationsBatched: number;
|
|
962
|
+
pendingQueueSize: number;
|
|
963
|
+
};
|
|
964
|
+
get(key: string): Promise<string | null>;
|
|
965
|
+
read(key: string, hash?: boolean): Promise<TimedRedisValue>;
|
|
966
|
+
setex(key: string, seconds: number, value: string): Promise<void>;
|
|
967
|
+
setpx(key: string, milliseconds: number, value: string): Promise<void>;
|
|
968
|
+
del(...keys: string[]): Promise<number>;
|
|
969
|
+
private supportsPipelines;
|
|
970
|
+
private enqueue;
|
|
971
|
+
flush(): Promise<void>;
|
|
972
|
+
private dispatch;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/** Default safety ceiling for autonomous L1 memory allocations: 512 MB */
|
|
976
|
+
declare const DEFAULT_AUTONOMOUS_L1_CEILING_BYTES: number;
|
|
977
|
+
/** Minimum floor for autonomous L1 allocations: 16 MB */
|
|
978
|
+
declare const MIN_AUTONOMOUS_L1_FLOOR_BYTES: number;
|
|
979
|
+
/**
|
|
980
|
+
* Reads the container memory limit from Linux cgroups (v2 or v1).
|
|
981
|
+
*
|
|
982
|
+
* Defaults to `Infinity` when running outside Linux, when cgroup limits are unset ('max'),
|
|
983
|
+
* or when permission errors (EACCES / ENOENT) occur in hardened distroless environments.
|
|
984
|
+
*/
|
|
985
|
+
declare function readCgroupMemoryLimit(): number;
|
|
986
|
+
/**
|
|
987
|
+
* Returns the V8 JavaScript heap size limit in bytes.
|
|
988
|
+
* Safely guards against missing or mock environments.
|
|
989
|
+
*/
|
|
990
|
+
declare function getV8HeapLimit(): number;
|
|
991
|
+
interface AutonomousL1Options {
|
|
992
|
+
cgroupLimit?: number;
|
|
993
|
+
v8HeapLimit?: number;
|
|
994
|
+
defaultCeilingBytes?: number;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Computes an autonomous, safe memory bound for TriCache L1 RAM.
|
|
998
|
+
*
|
|
999
|
+
* Evaluates both the container cgroup limit (max 40% of container RAM)
|
|
1000
|
+
* and the V8 heap limit (max 50% of V8 heap limit from --max-old-space-size),
|
|
1001
|
+
* capped at a default 512MB ceiling.
|
|
1002
|
+
*/
|
|
1003
|
+
declare function resolveAutonomousL1MaxBytes(options?: AutonomousL1Options): number;
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Lightweight W3C TraceContext (traceparent) helpers for distributed context propagation.
|
|
1007
|
+
*
|
|
1008
|
+
* Implements W3C Trace Context Level 1:
|
|
1009
|
+
* Format: {version}-{traceId}-{spanId}-{traceFlags}
|
|
1010
|
+
* Example: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01
|
|
1011
|
+
*/
|
|
1012
|
+
interface ParsedTraceParent {
|
|
1013
|
+
version: string;
|
|
1014
|
+
traceId: string;
|
|
1015
|
+
spanId: string;
|
|
1016
|
+
traceFlags: number;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Parses a standard W3C traceparent header string into its components.
|
|
1020
|
+
* Returns null if the header is malformed.
|
|
1021
|
+
*/
|
|
1022
|
+
declare function parseTraceParent(header: string | undefined | null): ParsedTraceParent | null;
|
|
1023
|
+
/**
|
|
1024
|
+
* Formats trace components into a valid W3C traceparent header string.
|
|
1025
|
+
*/
|
|
1026
|
+
declare function formatTraceParent(traceId: string, spanId: string, traceFlags?: number): string;
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* Utilities for wildcard matching and hierarchical cascading of cache tags.
|
|
1030
|
+
*/
|
|
1031
|
+
/**
|
|
1032
|
+
* Returns true if the given tag contains glob wildcard characters ('*' or '?').
|
|
1033
|
+
*/
|
|
1034
|
+
declare function isWildcardTag(tag: string): boolean;
|
|
1035
|
+
/**
|
|
1036
|
+
* Matches a tag name against a pattern supporting '*' (0 or more chars) and '?' (single char).
|
|
1037
|
+
* Optimized with fast-paths for exact match, universal wildcard, and single prefix/suffix wildcards.
|
|
1038
|
+
*/
|
|
1039
|
+
declare function matchesTagPattern(pattern: string, tag: string): boolean;
|
|
1040
|
+
/**
|
|
1041
|
+
* Determines whether `candidateTag` is either identical to `parentTag`
|
|
1042
|
+
* or a child descendant in the hierarchy separated by `delimiter`.
|
|
1043
|
+
*
|
|
1044
|
+
* Example:
|
|
1045
|
+
* isChildTag('org:123', 'org:123', ':') -> true
|
|
1046
|
+
* isChildTag('org:123', 'org:123:dept', ':') -> true
|
|
1047
|
+
* isChildTag('org:123', 'org:1234', ':') -> false (must match delimiter boundary)
|
|
1048
|
+
*/
|
|
1049
|
+
declare function isChildTag(parentTag: string, candidateTag: string, delimiter?: string): boolean;
|
|
1050
|
+
/**
|
|
1051
|
+
* Expands hierarchical tags into all ancestor namespace levels.
|
|
1052
|
+
*
|
|
1053
|
+
* Example:
|
|
1054
|
+
* expandHierarchicalTags(['org:123:dept:456', 'role:admin'], ':')
|
|
1055
|
+
* => ['org', 'org:123', 'org:123:dept', 'org:123:dept:456', 'role', 'role:admin']
|
|
1056
|
+
*/
|
|
1057
|
+
declare function expandHierarchicalTags(tags: string[], delimiter?: string): string[];
|
|
1058
|
+
|
|
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 };
|