tricache 1.0.0 → 1.0.2
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 +36 -28
- package/dist/{cache-service-pJ-nFcVj.d.ts → cache-service-B108FzER.d.ts} +63 -3
- package/dist/cache-service-CWI4jkS7.d.cts +963 -0
- package/dist/{cache-service-26GCO3UU.js → cache-service-GYPZFB7O.js} +2 -2
- package/dist/{chunk-IITRFWHY.js → chunk-EUKB7RKP.js} +21 -4
- package/dist/{chunk-2AJKEQMZ.js → chunk-H4GFLQ26.js} +7 -4
- package/dist/{chunk-7RV5ZVBB.js → chunk-JNSLMK4Q.js} +111 -29
- package/dist/chunk-OYDU3SMI.js +89 -0
- package/dist/{chunk-VXFTFZ5N.js → chunk-VNRDL5RA.js} +117 -138
- package/dist/{chunk-7SZSQS55.js → chunk-WYF7NOAT.js} +1831 -759
- package/dist/cli.cjs +1757 -777
- package/dist/cli.d.cts +12 -0
- package/dist/cli.js +27 -6
- 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 +1757 -773
- package/dist/drizzle/index.d.cts +46 -0
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/drizzle/index.js +1 -1
- package/dist/edge/index.cjs +280 -153
- package/dist/edge/index.d.cts +127 -0
- package/dist/edge/index.d.ts +3 -3
- package/dist/edge/index.js +254 -147
- package/dist/hono/index.cjs +1805 -793
- 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-DuNvciyq.d.ts → hono-3rDMYVtY.d.ts} +23 -3
- package/dist/hono-C886ok3X.d.cts +391 -0
- package/dist/http/index.cjs +1946 -842
- package/dist/http/index.d.cts +103 -0
- package/dist/http/index.d.ts +13 -5
- package/dist/http/index.js +137 -57
- package/dist/index.cjs +2073 -937
- package/dist/index.d.cts +1006 -0
- package/dist/index.d.ts +40 -8
- package/dist/index.js +8 -8
- package/dist/murmur3-CMGw9PbV.d.cts +98 -0
- package/dist/nestjs/index.cjs +1849 -806
- package/dist/nestjs/index.d.cts +285 -0
- package/dist/nestjs/index.d.ts +103 -30
- package/dist/nestjs/index.js +115 -32
- package/dist/next/index.cjs +1913 -887
- package/dist/next/index.d.cts +232 -0
- package/dist/next/index.d.ts +33 -11
- package/dist/next/index.js +174 -107
- package/dist/prisma/index.cjs +11 -1
- package/dist/prisma/index.d.cts +62 -0
- package/dist/prisma/index.d.ts +2 -2
- package/dist/prisma/index.js +11 -1
- package/dist/serialize-worker.d.cts +2 -0
- package/dist/{types-5HXqBfAf.d.ts → types-BA4pz1A0.d.cts} +26 -9
- package/dist/types-BA4pz1A0.d.ts +1519 -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 +96 -36
- package/src/adapters/auto-pipeliner.ts +107 -24
- package/src/adapters/node-redis.ts +123 -25
- package/src/cache-service.ts +1238 -659
- package/src/cli.ts +24 -6
- package/src/cross-region.ts +21 -3
- 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 +171 -65
- package/src/edge/cache.ts +202 -129
- package/src/edge/hono.ts +23 -6
- package/src/edge/types.ts +2 -0
- package/src/hono/index.ts +19 -9
- package/src/http/express.ts +110 -26
- package/src/http/fastify.ts +38 -28
- package/src/http/utils.ts +54 -20
- package/src/ipc-telemetry.ts +35 -9
- package/src/nestjs/decorators.ts +1 -1
- package/src/nestjs/index.ts +2 -0
- package/src/nestjs/keyv-adapter.ts +68 -0
- package/src/nestjs/tricache.module.ts +13 -11
- package/src/nestjs/tricache.store.ts +51 -20
- package/src/nestjs/types.ts +29 -15
- package/src/next/cache-handler.ts +132 -57
- package/src/next/index.ts +1 -0
- package/src/next/isr-handler.ts +1 -4
- package/src/next/types.ts +21 -0
- package/src/prisma/index.ts +12 -1
- package/src/smart-memory-cache.ts +65 -27
- package/src/types.ts +27 -2
- package/src/utils/cgroup.ts +12 -0
- package/src/utils/deadline.ts +14 -0
- package/src/utils/diagnostics.ts +27 -0
- package/src/utils/redis-slot.ts +13 -0
- package/src/wasm/bloom-filter-wasm.ts +9 -4
- package/src/worker-pool.ts +17 -8
- package/src/wtiny-lfu.ts +20 -6
- package/dist/chunk-BQRURGGD.js +0 -60
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://kareem411.github.io/TriCache/)
|
|
5
5
|
[](https://www.npmjs.com/package/tricache)
|
|
6
6
|
[](https://www.npmjs.com/package/tricache)
|
|
7
|
-
[](tests)
|
|
8
8
|
[](src)
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](https://nodejs.org)
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
> 🌐 **Documentation Site**: **[https://kareem411.github.io/TriCache/](https://kareem411.github.io/TriCache/)**
|
|
13
13
|
> 📦 **npm Package**: **[`npm install tricache`](https://www.npmjs.com/package/tricache)**
|
|
14
14
|
|
|
15
|
-
**TriCache** is
|
|
15
|
+
**TriCache** is a three-tier caching engine for Node.js: **L1 RAM** $\rightarrow$ **L1.5 disk or `/dev/shm` spill** $\rightarrow$ **L2 Redis/Valkey**. It combines bounded local storage, per-process singleflight, configurable stale-while-revalidate, and distributed invalidation. Performance and savings depend on your workload; [benchmark your deployment](BENCHMARKS.md).
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
@@ -27,16 +27,17 @@ import { CacheService } from 'tricache';
|
|
|
27
27
|
|
|
28
28
|
// 1. One-line preset: W-TinyLFU, Redis Streams, /dev/shm off-heap spill, & SWR
|
|
29
29
|
const cache = CacheService.preset('nextjs', { redisHost: process.env.REDIS_HOST });
|
|
30
|
+
await cache.ready();
|
|
30
31
|
|
|
31
32
|
// 2. Get-or-fetch with thundering-herd coalescing & 60s background SWR
|
|
32
33
|
const user = await cache.get(
|
|
33
34
|
`user:${userId}`,
|
|
34
35
|
() => db.users.findById(userId),
|
|
35
36
|
300, // 5-minute TTL
|
|
36
|
-
{ swr: 60 } // Serve stale for 60s while refreshing in the background
|
|
37
|
+
{ swr: 60, tags: ['users'] } // Serve stale for 60s while refreshing in the background
|
|
37
38
|
);
|
|
38
39
|
|
|
39
|
-
// 3.
|
|
40
|
+
// 3. Bump a concrete tag generation and publish invalidation to peers
|
|
40
41
|
await cache.invalidateTag('users');
|
|
41
42
|
```
|
|
42
43
|
|
|
@@ -49,26 +50,26 @@ await cache.invalidateTag('users');
|
|
|
49
50
|
│
|
|
50
51
|
▼
|
|
51
52
|
┌──────────────────────────────────────────────────┐
|
|
52
|
-
│ L1: Smart Memory (W-TinyLFU + CMS) │
|
|
53
|
-
│ Window LRU (1%) + Segmented Main SLRU (99%) │
|
|
53
|
+
│ L1: Smart Memory (W-TinyLFU + CMS) │ Bounded RAM
|
|
54
|
+
│ Window LRU (1%) + Segmented Main SLRU (99%) │ Packed values
|
|
54
55
|
└────────────────────────┬─────────────────────────┘
|
|
55
56
|
│ Miss / Eviction Spill
|
|
56
57
|
▼
|
|
57
58
|
┌──────────────────────────────────────────────────┐
|
|
58
|
-
│ L1.5: Off-Heap /dev/shm & NVMe Spill Tier │
|
|
59
|
-
│
|
|
59
|
+
│ L1.5: Off-Heap /dev/shm & NVMe Spill Tier │ Bounded I/O
|
|
60
|
+
│ tmpfs counts toward container memory usage │ Writable mount needed
|
|
60
61
|
└────────────────────────┬─────────────────────────┘
|
|
61
62
|
│ Miss
|
|
62
63
|
▼
|
|
63
64
|
┌──────────────────────────────────────────────────┐
|
|
64
65
|
│ L2: Redis / Valkey Distributed Tier │ ~1.2 ms (Network)
|
|
65
|
-
│ AES-
|
|
66
|
+
│ Optional AES-GCM + expiry/tag metadata │ Pipelined commands
|
|
66
67
|
└────────────────────────┬─────────────────────────┘
|
|
67
68
|
│ Complete Cache Miss
|
|
68
69
|
▼
|
|
69
70
|
┌──────────────────────────────────────────────────┐
|
|
70
|
-
│ Upstream Database / API (Singleflight
|
|
71
|
-
│ Inflight Promise Map coalesces
|
|
71
|
+
│ Upstream Database / API (Singleflight) │ Per process/key
|
|
72
|
+
│ Inflight Promise Map coalesces concurrent work│ Not a fleet-wide lock
|
|
72
73
|
└──────────────────────────────────────────────────┘
|
|
73
74
|
```
|
|
74
75
|
|
|
@@ -77,32 +78,31 @@ await cache.invalidateTag('users');
|
|
|
77
78
|
* **Off-Heap `/dev/shm` RAM Spill**: Targets Linux POSIX shared memory tmpfs ($\ge 256\text{MB}$ total, $\ge 128\text{MB}$ free), burning 0 cloud IOPS. [[SRE Guide $\rightarrow$](https://kareem411.github.io/TriCache/kubernetes-production-guide)]
|
|
78
79
|
* **Dynamic Latency Watchdog**: Graduated shedding (0% $\rightarrow$ 25% $\rightarrow$ 75% $\rightarrow$ 100%) with asymmetric Redis hysteresis (15ms cutoff, 10ms recovery floor).
|
|
79
80
|
* **Ephemeral Quotas & K8s Eviction Defense**: Chunked watermark pruning (80% $\rightarrow$ 60% in 500-entry batches) and proactive $<10\%$ space spill pauses.
|
|
80
|
-
* **Wildcard & Hierarchical Tag Invalidation**:
|
|
81
|
+
* **Wildcard & Hierarchical Tag Invalidation**: Concrete generation bumps are $O(1)$; wildcard and hierarchy resolution scan matching tag metadata.
|
|
81
82
|
* **Differential Multi-Tier Waterfall Batching**: Cascading `cache.mget` resolves L1 $\rightarrow$ L2 $\rightarrow$ Disk $\rightarrow$ DB miss fetch with zero $N+1$ queries.
|
|
82
83
|
* **Zero-Dependency Cloud Hydration (SigV4)**: Hydrates cold pods from S3/R2 in milliseconds via native Web Crypto. [[Cloud Guide $\rightarrow$](https://kareem411.github.io/TriCache/cold-start-cloud-hydration)]
|
|
83
84
|
|
|
84
85
|
---
|
|
85
86
|
|
|
86
|
-
## 🏆 Feature
|
|
87
|
+
## 🏆 Feature Overview
|
|
87
88
|
|
|
88
|
-
|
|
|
89
|
-
|
|
90
|
-
| **Storage
|
|
91
|
-
| **
|
|
92
|
-
| **
|
|
93
|
-
| **
|
|
94
|
-
| **
|
|
95
|
-
| **
|
|
96
|
-
| **
|
|
97
|
-
| **
|
|
98
|
-
| **Encryption at Rest** | ❌ None | ❌ None | ❌ None | **✅ AES-256-GCM / Web Crypto AEAD** |
|
|
89
|
+
| Feature | Behavior |
|
|
90
|
+
|:---|:---|
|
|
91
|
+
| **Storage hierarchy** | RAM → eligible disk/tmpfs spill → Redis/Valkey |
|
|
92
|
+
| **Singleflight** | Coalesces concurrent work per process and key |
|
|
93
|
+
| **Tag invalidation** | Concrete generation bumps; metadata scans for patterns/cascades |
|
|
94
|
+
| **Backplane** | Pub/Sub or retained-event Redis Streams replay |
|
|
95
|
+
| **Compression** | Zstandard with fallback; optional Brotli, gzip, LZ4, or custom compressor |
|
|
96
|
+
| **Batch reads** | Resolves cached keys and fetches only remaining misses |
|
|
97
|
+
| **Resource controls** | Packed-data limits, bounded disk I/O, and cgroup pressure guards |
|
|
98
|
+
| **Encryption** | Optional AES-GCM for Node and Web Crypto edge storage |
|
|
99
99
|
|
|
100
100
|
---
|
|
101
101
|
|
|
102
102
|
## 🎯 Production Presets (`CacheService.preset`)
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
|
-
// 1. Next.js 16
|
|
105
|
+
// 1. Next.js 16 App Router (React 19 RSC streams & generational tags)
|
|
106
106
|
const cache = CacheService.preset('nextjs', { redisHost: 'redis.internal' });
|
|
107
107
|
|
|
108
108
|
// 2. High-Throughput Microservice (Streams backplane, TTL jitter, circuit breakers)
|
|
@@ -121,16 +121,24 @@ const cache = CacheService.preset('enterprise-hardened', { redisHost: 'redis.int
|
|
|
121
121
|
|
|
122
122
|
| Integration | Import Path | Description |
|
|
123
123
|
|:---|:---|:---|
|
|
124
|
-
| **Next.js 16
|
|
125
|
-
| **NestJS
|
|
124
|
+
| **Next.js 16** | `tricache/next` | Native Cache Components `cacheHandlers` with bounded RSC streams, timing preservation, and soft-tag expiry. |
|
|
125
|
+
| **NestJS 10–12** | `tricache/nestjs` | `TriCacheModule`, millisecond TTL facade, Keyv 5/cache-manager 7 adapter, and `@Cacheable`. |
|
|
126
126
|
| **Prisma ORM** | `tricache/prisma` | `$extends` client extension with query hashing and auto-mutation tag eviction. |
|
|
127
127
|
| **Drizzle ORM** | `tricache/drizzle` | `withCache(query, opts)` query wrapper with SQL+parameters hashing and background SWR. |
|
|
128
128
|
| **Express & Fastify** | `tricache/http` | Route caching middleware with deterministic query sorting, weak ETag, and `304 Not Modified`. |
|
|
129
|
-
| **Node Hono** | `tricache/hono` |
|
|
129
|
+
| **Node Hono** | `tricache/hono` | Response caching with TTL/tags, privacy guards, and `304 Not Modified`. |
|
|
130
130
|
| **Edge Isolates & Hono** | `tricache/edge` | Zero-Node-dependency implementation for Cloudflare Workers, Fastly Compute, Hono, and Vercel Edge. |
|
|
131
131
|
| **SSE Dashboard** | `tricache/dashboard` | Zero-dependency Server-Sent Events real-time admin dashboard. |
|
|
132
132
|
| **Live CLI Top** | `npx tricache top` | Real-time terminal ASCII monitor over Unix sockets and Windows named pipes. |
|
|
133
133
|
|
|
134
|
+
### Safety and consistency
|
|
135
|
+
|
|
136
|
+
- HTTP middleware bypasses credentialed requests by default and excludes private, cookie-setting, partial, and unkeyed `Vary` responses. Response refreshes run on live requests; use `cache.get()`/`wrap()` for data-level SWR.
|
|
137
|
+
- Dashboard access should be authenticated and private. It defaults to `readOnly: true`; administrative writes require explicit opt-in.
|
|
138
|
+
- Redis Streams provide replay only while events are retained. A detected gap flushes local state. `awaitInvalidationBackplane: true` confirms publication, not peer acknowledgments or exactly-once delivery.
|
|
139
|
+
- Redis promotions preserve remaining TTL where supported. Custom drivers without atomic expiry reads use fallback TTLs; edge legacy JSON without expiry metadata is read without local promotion.
|
|
140
|
+
- `/dev/shm` reduces disk I/O but still consumes container memory. Encryption and cache configuration do not by themselves establish regulatory compliance.
|
|
141
|
+
|
|
134
142
|
---
|
|
135
143
|
|
|
136
144
|
## 📚 Documentation & Deep Dives
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as CacheOptions, b as CacheMetrics, c as CacheHealthStatus, d as CachePresetType, e as CrossRegionInvalidationEvent, f as CachePriority, W as WrapOptions, a as InvalidateTagOptions, g as CachePingResult, D as DiskBackpressureStats, L as LockOptions, E as EncryptionMode, h as WTinyLfuStats } from './types-
|
|
1
|
+
import { C as CacheOptions, b as CacheMetrics, c as CacheHealthStatus, d as CachePresetType, e as CrossRegionInvalidationEvent, f as CachePriority, W as WrapOptions, a as InvalidateTagOptions, g as CachePingResult, D as DiskBackpressureStats, L as LockOptions, E as EncryptionMode, h as WTinyLfuStats } from './types-BA4pz1A0.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* TierLatencyWatchdog — Graduated, self-healing tier latency watchdog.
|
|
@@ -141,6 +141,8 @@ declare class IpcTelemetryServer {
|
|
|
141
141
|
private server;
|
|
142
142
|
readonly socketPath: string;
|
|
143
143
|
private _closed;
|
|
144
|
+
private _starting;
|
|
145
|
+
private readonly sockets;
|
|
144
146
|
private _exitHandler;
|
|
145
147
|
private _sigintHandler;
|
|
146
148
|
private _sigtermHandler;
|
|
@@ -149,6 +151,7 @@ declare class IpcTelemetryServer {
|
|
|
149
151
|
* Start listening on the IPC socket / pipe.
|
|
150
152
|
*/
|
|
151
153
|
start(): Promise<void>;
|
|
154
|
+
private startInternal;
|
|
152
155
|
/**
|
|
153
156
|
* Build a complete telemetry snapshot from the underlying cache provider.
|
|
154
157
|
*/
|
|
@@ -237,13 +240,19 @@ declare class CacheService {
|
|
|
237
240
|
private readonly _l1Counters;
|
|
238
241
|
/** tag → Set of namespaced cache keys; maintained in-process for O(1) invalidateTag() */
|
|
239
242
|
private readonly tagIndex;
|
|
243
|
+
/** Reverse index of namespaced key → { tags, expiresAt } for bounded cleanup on eviction/delete */
|
|
244
|
+
private readonly keyTags;
|
|
240
245
|
/** tag → { version, lastSyncedAt } for generational tag invalidation (bounded to 10,000 entries) */
|
|
241
246
|
private readonly tagVersions;
|
|
247
|
+
private _tagRefreshEpoch;
|
|
242
248
|
/**
|
|
243
249
|
* Dependency index: source glob pattern → Set of namespaced dependent keys.
|
|
244
250
|
* When an exact-key delete matches a registered pattern, all dependents are cascaded.
|
|
245
251
|
*/
|
|
246
252
|
private readonly dependencyIndex;
|
|
253
|
+
/** Reverse index of namespaced dependent key → source glob patterns */
|
|
254
|
+
private readonly keyDependencies;
|
|
255
|
+
private readonly _cgroupMemoryLimit;
|
|
247
256
|
private redis;
|
|
248
257
|
private redisConnecting;
|
|
249
258
|
private readonly cb;
|
|
@@ -266,9 +275,17 @@ declare class CacheService {
|
|
|
266
275
|
private subClient;
|
|
267
276
|
private streamClient;
|
|
268
277
|
private _lastStreamId;
|
|
278
|
+
private _restoredSnapshot;
|
|
279
|
+
private _backplaneAvailable;
|
|
280
|
+
private _otelCleanup;
|
|
281
|
+
private _streamRecovering;
|
|
282
|
+
private readonly _backplaneDisposers;
|
|
269
283
|
private _destroyed;
|
|
270
284
|
private readonly _pendingDiskDeletes;
|
|
271
285
|
private _globalEpoch;
|
|
286
|
+
private _pendingSpillCount;
|
|
287
|
+
private _suppressSpills;
|
|
288
|
+
private _diskCleanupScheduled;
|
|
272
289
|
private readonly _keyMutationEpochs;
|
|
273
290
|
/**
|
|
274
291
|
* Pattern tombstones for disk tier.
|
|
@@ -277,11 +294,28 @@ declare class CacheService {
|
|
|
277
294
|
* pattern tombstones in memory to intercept subsequent disk reads and evict matching files.
|
|
278
295
|
*/
|
|
279
296
|
private readonly _patternTombstones;
|
|
297
|
+
private _diskInvalidatedBefore;
|
|
280
298
|
private _addPatternTombstone;
|
|
281
299
|
private _isTombstonedByPattern;
|
|
282
300
|
private _assertActive;
|
|
283
301
|
private _bumpKeyMutation;
|
|
284
302
|
private _getKeyMutationEpoch;
|
|
303
|
+
/** Capture a commit fence before asynchronous computation outside the cache. */
|
|
304
|
+
captureMutationFence(cacheKey: string): () => boolean;
|
|
305
|
+
/** Force tag re-sync without forgetting locally observed monotonic generations. */
|
|
306
|
+
refreshTagVersions(): void;
|
|
307
|
+
private _fenceInvalidation;
|
|
308
|
+
private _invalidateDiskKey;
|
|
309
|
+
private _scheduleDiskCleanup;
|
|
310
|
+
private _registerDependencies;
|
|
311
|
+
private _rememberTags;
|
|
312
|
+
private _restoreEntryMetadata;
|
|
313
|
+
private _removeKeyTags;
|
|
314
|
+
private _removeKeyDependencies;
|
|
315
|
+
private _handleL1Eviction;
|
|
316
|
+
private _removePatternFromIndices;
|
|
317
|
+
private _sweepExpiredMetadata;
|
|
318
|
+
private _runOomCheck;
|
|
285
319
|
private _ipcServer?;
|
|
286
320
|
/** Timestamp (Date.now()) when the backplane subscriber last lost its connection. */
|
|
287
321
|
private _subDisconnectedAt;
|
|
@@ -331,7 +365,7 @@ declare class CacheService {
|
|
|
331
365
|
private static optionsDiff;
|
|
332
366
|
/** Increment the singleton-divergence counter (surfaced in `metrics()`). */
|
|
333
367
|
bumpSingletonDivergence(): void;
|
|
334
|
-
/**
|
|
368
|
+
/** Sanitized diagnostic view; retain the original options/adapters to reuse configuration. */
|
|
335
369
|
get options(): CacheOptions;
|
|
336
370
|
/**
|
|
337
371
|
* Async factory — accepts a Promise that resolves to CacheOptions.
|
|
@@ -363,7 +397,9 @@ declare class CacheService {
|
|
|
363
397
|
/** Start an OTEL-compatible span if a tracer is configured. Returns a no-op span otherwise. */
|
|
364
398
|
private _startSpan;
|
|
365
399
|
private createDedicatedRedisClient;
|
|
400
|
+
private _listenBackplane;
|
|
366
401
|
private initBackplane;
|
|
402
|
+
private _resetAfterStreamGap;
|
|
367
403
|
private _startStreamConsumer;
|
|
368
404
|
/**
|
|
369
405
|
* Validate + apply one XREAD stream entry. `fields` is the flat ioredis
|
|
@@ -390,7 +426,16 @@ declare class CacheService {
|
|
|
390
426
|
*/
|
|
391
427
|
receiveCrossRegionInvalidation(event: CrossRegionInvalidationEvent): Promise<boolean>;
|
|
392
428
|
private _setLocalTagVersion;
|
|
429
|
+
private _isGenerationalEntryStale;
|
|
430
|
+
private _deleteRedisKeys;
|
|
431
|
+
private _parseGenerationalRedisHash;
|
|
432
|
+
private _readRedisEntry;
|
|
393
433
|
private _getTagVersion;
|
|
434
|
+
private _readRedisBatch;
|
|
435
|
+
private _promoteRedisEntry;
|
|
436
|
+
private _readDiskEntry;
|
|
437
|
+
/** Common write policy and metadata across get/set/revalidation/draining. */
|
|
438
|
+
private _writeRedisEntry;
|
|
394
439
|
private _deleteIfStale;
|
|
395
440
|
/**
|
|
396
441
|
* Serialize payload for L2 Redis storage applying compression and encryption as configured.
|
|
@@ -467,6 +512,8 @@ declare class CacheService {
|
|
|
467
512
|
* On an L1/L2 hit the tags are already registered — this field is a no-op for hits.
|
|
468
513
|
*/
|
|
469
514
|
tags?: string[];
|
|
515
|
+
/** Dependency patterns registered when a miss populates the entry. */
|
|
516
|
+
dependsOn?: string[];
|
|
470
517
|
}): Promise<T>;
|
|
471
518
|
/**
|
|
472
519
|
* Graceful shutdown flusher for Kubernetes preStop hooks, NestJS onApplicationShutdown,
|
|
@@ -606,7 +653,7 @@ declare class CacheService {
|
|
|
606
653
|
*/
|
|
607
654
|
scan<T = unknown>(fn: (rawKey: string, value: T, offset: number) => void): void;
|
|
608
655
|
/**
|
|
609
|
-
|
|
656
|
+
* Extend the TTL of a key in L1 and Redis without fetching.
|
|
610
657
|
* Returns `false` if the key is absent or already expired.
|
|
611
658
|
*
|
|
612
659
|
* @param newTtlSeconds - The new TTL from now, in seconds.
|
|
@@ -621,6 +668,7 @@ declare class CacheService {
|
|
|
621
668
|
* if (fresh !== null) return fresh; // serve from L1, no network hop
|
|
622
669
|
*/
|
|
623
670
|
getIfFresh<T = unknown>(cacheKey: string): T | null;
|
|
671
|
+
private _prepareReadValue;
|
|
624
672
|
/**
|
|
625
673
|
* Pure read across cache tiers (L1 RAM → L1.5 Disk → L2 Redis) without invoking a fetcher.
|
|
626
674
|
* Returns the cached value if found and valid, or `null` if absent / expired.
|
|
@@ -698,6 +746,18 @@ declare class CacheService {
|
|
|
698
746
|
* Scans local in-memory indices (tagIndex, tagVersions, L1 entries) and Redis (if connected).
|
|
699
747
|
*/
|
|
700
748
|
private _resolveMatchingTags;
|
|
749
|
+
private _publishTagInvalidation;
|
|
750
|
+
private _removeTagMembersLocal;
|
|
751
|
+
/**
|
|
752
|
+
* Executes invalidation for a single already-resolved concrete tag without
|
|
753
|
+
* wildcard/cascade re-resolution, avoiding mutual recursion with invalidateTags().
|
|
754
|
+
*/
|
|
755
|
+
private _invalidateConcreteTag;
|
|
756
|
+
/**
|
|
757
|
+
* Executes invalidation for an array of already-resolved concrete tags
|
|
758
|
+
* without re-entering wildcard/cascade resolution or invalidateTag().
|
|
759
|
+
*/
|
|
760
|
+
private _invalidateConcreteTags;
|
|
701
761
|
/**
|
|
702
762
|
* Invalidate all keys associated with a tag, wildcard glob pattern, or hierarchical namespace.
|
|
703
763
|
* Deletes from L1, disk, and Redis (both the keyed values and the tag metadata).
|