layercache 1.2.2 → 1.2.4
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 +119 -89
- package/dist/{chunk-ZMDB5KOK.js → chunk-7V7XAB74.js} +24 -1
- package/dist/{chunk-46UH7LNM.js → chunk-KOYGHLVP.js} +142 -18
- package/dist/{chunk-IXCMHVHP.js → chunk-QHWG7QS5.js} +1 -1
- package/dist/cli.cjs +37 -3
- package/dist/cli.js +15 -4
- package/dist/{edge-DLpdQN0W.d.ts → edge-Dw97n89L.d.cts} +33 -1
- package/dist/{edge-DLpdQN0W.d.cts → edge-Dw97n89L.d.ts} +33 -1
- package/dist/edge.cjs +165 -17
- package/dist/edge.d.cts +1 -1
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +2 -2
- package/dist/index.cjs +657 -146
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +447 -84
- package/package.json +4 -4
- package/packages/nestjs/dist/index.cjs +558 -91
- package/packages/nestjs/dist/index.d.cts +24 -0
- package/packages/nestjs/dist/index.d.ts +24 -0
- package/packages/nestjs/dist/index.js +558 -91
|
@@ -168,6 +168,7 @@ interface CacheStackOptions {
|
|
|
168
168
|
invalidationBus?: InvalidationBus;
|
|
169
169
|
tagIndex?: CacheTagIndex;
|
|
170
170
|
generation?: number;
|
|
171
|
+
generationCleanup?: boolean | CacheGenerationCleanupOptions;
|
|
171
172
|
broadcastL1Invalidation?: boolean;
|
|
172
173
|
/**
|
|
173
174
|
* @deprecated Use `broadcastL1Invalidation` instead.
|
|
@@ -186,11 +187,13 @@ interface CacheStackOptions {
|
|
|
186
187
|
writeStrategy?: 'write-through' | 'write-behind';
|
|
187
188
|
writeBehind?: CacheWriteBehindOptions;
|
|
188
189
|
fetcherRateLimit?: CacheRateLimitOptions;
|
|
190
|
+
backgroundRefreshTimeoutMs?: number;
|
|
189
191
|
singleFlightCoordinator?: CacheSingleFlightCoordinator;
|
|
190
192
|
singleFlightLeaseMs?: number;
|
|
191
193
|
singleFlightTimeoutMs?: number;
|
|
192
194
|
singleFlightPollMs?: number;
|
|
193
195
|
singleFlightRenewIntervalMs?: number;
|
|
196
|
+
snapshotBaseDir?: string | false;
|
|
194
197
|
/**
|
|
195
198
|
* Maximum number of entries in `accessProfiles` and `circuitBreakers` maps
|
|
196
199
|
* before the oldest entries are pruned. Prevents unbounded memory growth.
|
|
@@ -203,6 +206,9 @@ interface CacheAdaptiveTtlOptions {
|
|
|
203
206
|
step?: number | LayerTtlMap;
|
|
204
207
|
maxTtl?: number | LayerTtlMap;
|
|
205
208
|
}
|
|
209
|
+
interface CacheGenerationCleanupOptions {
|
|
210
|
+
batchSize?: number;
|
|
211
|
+
}
|
|
206
212
|
type CacheTtlPolicy = 'until-midnight' | 'next-hour' | {
|
|
207
213
|
alignTo: number;
|
|
208
214
|
} | ((context: CacheTtlPolicyContext) => number | undefined);
|
|
@@ -404,7 +410,9 @@ declare class CacheStack extends EventEmitter {
|
|
|
404
410
|
private unsubscribeInvalidation?;
|
|
405
411
|
private readonly logger;
|
|
406
412
|
private readonly tagIndex;
|
|
413
|
+
private readonly keyDiscovery;
|
|
407
414
|
private readonly fetchRateLimiter;
|
|
415
|
+
private readonly snapshotSerializer;
|
|
408
416
|
private readonly backgroundRefreshes;
|
|
409
417
|
private readonly layerDegradedUntil;
|
|
410
418
|
private readonly ttlResolver;
|
|
@@ -413,6 +421,7 @@ declare class CacheStack extends EventEmitter {
|
|
|
413
421
|
private readonly writeBehindQueue;
|
|
414
422
|
private writeBehindTimer?;
|
|
415
423
|
private writeBehindFlushPromise?;
|
|
424
|
+
private generationCleanupPromise?;
|
|
416
425
|
private isDisconnecting;
|
|
417
426
|
private disconnectPromise?;
|
|
418
427
|
constructor(layers: CacheLayer[], options?: CacheStackOptions);
|
|
@@ -423,6 +432,7 @@ declare class CacheStack extends EventEmitter {
|
|
|
423
432
|
* and no `fetcher` is provided.
|
|
424
433
|
*/
|
|
425
434
|
get<T>(key: string, fetcher?: () => Promise<T>, options?: CacheGetOptions): Promise<T | null>;
|
|
435
|
+
private getPrepared;
|
|
426
436
|
/**
|
|
427
437
|
* Alias for `get(key, fetcher, options)` — explicit get-or-set pattern.
|
|
428
438
|
* Fetches and caches the value if not already present.
|
|
@@ -481,6 +491,11 @@ declare class CacheStack extends EventEmitter {
|
|
|
481
491
|
*/
|
|
482
492
|
getHitRate(): CacheHitRateSnapshot;
|
|
483
493
|
healthCheck(): Promise<CacheHealthCheckResult[]>;
|
|
494
|
+
/**
|
|
495
|
+
* Rotates the active generation prefix used for all future cache keys.
|
|
496
|
+
* Previous-generation keys remain in the underlying layers until they expire,
|
|
497
|
+
* unless `generationCleanup` is enabled to prune them in the background.
|
|
498
|
+
*/
|
|
484
499
|
bumpGeneration(nextGeneration?: number): number;
|
|
485
500
|
/**
|
|
486
501
|
* Returns detailed metadata about a single cache key: which layers contain it,
|
|
@@ -508,6 +523,7 @@ declare class CacheStack extends EventEmitter {
|
|
|
508
523
|
private resolveLayerSeconds;
|
|
509
524
|
private shouldNegativeCache;
|
|
510
525
|
private scheduleBackgroundRefresh;
|
|
526
|
+
private runBackgroundRefresh;
|
|
511
527
|
private resolveSingleFlightOptions;
|
|
512
528
|
private deleteKeys;
|
|
513
529
|
private publishInvalidation;
|
|
@@ -515,7 +531,12 @@ declare class CacheStack extends EventEmitter {
|
|
|
515
531
|
private getTagsForKey;
|
|
516
532
|
private formatError;
|
|
517
533
|
private sleep;
|
|
534
|
+
private withTimeout;
|
|
518
535
|
private shouldBroadcastL1Invalidation;
|
|
536
|
+
private shouldCleanupGenerations;
|
|
537
|
+
private generationCleanupBatchSize;
|
|
538
|
+
private scheduleGenerationCleanup;
|
|
539
|
+
private cleanupGeneration;
|
|
519
540
|
private initializeWriteBehind;
|
|
520
541
|
private shouldWriteBehind;
|
|
521
542
|
private enqueueWriteBehind;
|
|
@@ -543,12 +564,15 @@ declare class CacheStack extends EventEmitter {
|
|
|
543
564
|
private applyFreshReadPolicies;
|
|
544
565
|
private shouldSkipLayer;
|
|
545
566
|
private handleLayerFailure;
|
|
567
|
+
private reportRecoverableLayerFailure;
|
|
546
568
|
private isGracefulDegradationEnabled;
|
|
547
569
|
private recordCircuitFailure;
|
|
548
570
|
private isNegativeStoredValue;
|
|
549
571
|
private emitError;
|
|
550
572
|
private serializeKeyPart;
|
|
551
573
|
private isCacheSnapshotEntries;
|
|
574
|
+
private sanitizeSnapshotValue;
|
|
575
|
+
private validateSnapshotFilePath;
|
|
552
576
|
private normalizeForSerialization;
|
|
553
577
|
}
|
|
554
578
|
|
|
@@ -168,6 +168,7 @@ interface CacheStackOptions {
|
|
|
168
168
|
invalidationBus?: InvalidationBus;
|
|
169
169
|
tagIndex?: CacheTagIndex;
|
|
170
170
|
generation?: number;
|
|
171
|
+
generationCleanup?: boolean | CacheGenerationCleanupOptions;
|
|
171
172
|
broadcastL1Invalidation?: boolean;
|
|
172
173
|
/**
|
|
173
174
|
* @deprecated Use `broadcastL1Invalidation` instead.
|
|
@@ -186,11 +187,13 @@ interface CacheStackOptions {
|
|
|
186
187
|
writeStrategy?: 'write-through' | 'write-behind';
|
|
187
188
|
writeBehind?: CacheWriteBehindOptions;
|
|
188
189
|
fetcherRateLimit?: CacheRateLimitOptions;
|
|
190
|
+
backgroundRefreshTimeoutMs?: number;
|
|
189
191
|
singleFlightCoordinator?: CacheSingleFlightCoordinator;
|
|
190
192
|
singleFlightLeaseMs?: number;
|
|
191
193
|
singleFlightTimeoutMs?: number;
|
|
192
194
|
singleFlightPollMs?: number;
|
|
193
195
|
singleFlightRenewIntervalMs?: number;
|
|
196
|
+
snapshotBaseDir?: string | false;
|
|
194
197
|
/**
|
|
195
198
|
* Maximum number of entries in `accessProfiles` and `circuitBreakers` maps
|
|
196
199
|
* before the oldest entries are pruned. Prevents unbounded memory growth.
|
|
@@ -203,6 +206,9 @@ interface CacheAdaptiveTtlOptions {
|
|
|
203
206
|
step?: number | LayerTtlMap;
|
|
204
207
|
maxTtl?: number | LayerTtlMap;
|
|
205
208
|
}
|
|
209
|
+
interface CacheGenerationCleanupOptions {
|
|
210
|
+
batchSize?: number;
|
|
211
|
+
}
|
|
206
212
|
type CacheTtlPolicy = 'until-midnight' | 'next-hour' | {
|
|
207
213
|
alignTo: number;
|
|
208
214
|
} | ((context: CacheTtlPolicyContext) => number | undefined);
|
|
@@ -404,7 +410,9 @@ declare class CacheStack extends EventEmitter {
|
|
|
404
410
|
private unsubscribeInvalidation?;
|
|
405
411
|
private readonly logger;
|
|
406
412
|
private readonly tagIndex;
|
|
413
|
+
private readonly keyDiscovery;
|
|
407
414
|
private readonly fetchRateLimiter;
|
|
415
|
+
private readonly snapshotSerializer;
|
|
408
416
|
private readonly backgroundRefreshes;
|
|
409
417
|
private readonly layerDegradedUntil;
|
|
410
418
|
private readonly ttlResolver;
|
|
@@ -413,6 +421,7 @@ declare class CacheStack extends EventEmitter {
|
|
|
413
421
|
private readonly writeBehindQueue;
|
|
414
422
|
private writeBehindTimer?;
|
|
415
423
|
private writeBehindFlushPromise?;
|
|
424
|
+
private generationCleanupPromise?;
|
|
416
425
|
private isDisconnecting;
|
|
417
426
|
private disconnectPromise?;
|
|
418
427
|
constructor(layers: CacheLayer[], options?: CacheStackOptions);
|
|
@@ -423,6 +432,7 @@ declare class CacheStack extends EventEmitter {
|
|
|
423
432
|
* and no `fetcher` is provided.
|
|
424
433
|
*/
|
|
425
434
|
get<T>(key: string, fetcher?: () => Promise<T>, options?: CacheGetOptions): Promise<T | null>;
|
|
435
|
+
private getPrepared;
|
|
426
436
|
/**
|
|
427
437
|
* Alias for `get(key, fetcher, options)` — explicit get-or-set pattern.
|
|
428
438
|
* Fetches and caches the value if not already present.
|
|
@@ -481,6 +491,11 @@ declare class CacheStack extends EventEmitter {
|
|
|
481
491
|
*/
|
|
482
492
|
getHitRate(): CacheHitRateSnapshot;
|
|
483
493
|
healthCheck(): Promise<CacheHealthCheckResult[]>;
|
|
494
|
+
/**
|
|
495
|
+
* Rotates the active generation prefix used for all future cache keys.
|
|
496
|
+
* Previous-generation keys remain in the underlying layers until they expire,
|
|
497
|
+
* unless `generationCleanup` is enabled to prune them in the background.
|
|
498
|
+
*/
|
|
484
499
|
bumpGeneration(nextGeneration?: number): number;
|
|
485
500
|
/**
|
|
486
501
|
* Returns detailed metadata about a single cache key: which layers contain it,
|
|
@@ -508,6 +523,7 @@ declare class CacheStack extends EventEmitter {
|
|
|
508
523
|
private resolveLayerSeconds;
|
|
509
524
|
private shouldNegativeCache;
|
|
510
525
|
private scheduleBackgroundRefresh;
|
|
526
|
+
private runBackgroundRefresh;
|
|
511
527
|
private resolveSingleFlightOptions;
|
|
512
528
|
private deleteKeys;
|
|
513
529
|
private publishInvalidation;
|
|
@@ -515,7 +531,12 @@ declare class CacheStack extends EventEmitter {
|
|
|
515
531
|
private getTagsForKey;
|
|
516
532
|
private formatError;
|
|
517
533
|
private sleep;
|
|
534
|
+
private withTimeout;
|
|
518
535
|
private shouldBroadcastL1Invalidation;
|
|
536
|
+
private shouldCleanupGenerations;
|
|
537
|
+
private generationCleanupBatchSize;
|
|
538
|
+
private scheduleGenerationCleanup;
|
|
539
|
+
private cleanupGeneration;
|
|
519
540
|
private initializeWriteBehind;
|
|
520
541
|
private shouldWriteBehind;
|
|
521
542
|
private enqueueWriteBehind;
|
|
@@ -543,12 +564,15 @@ declare class CacheStack extends EventEmitter {
|
|
|
543
564
|
private applyFreshReadPolicies;
|
|
544
565
|
private shouldSkipLayer;
|
|
545
566
|
private handleLayerFailure;
|
|
567
|
+
private reportRecoverableLayerFailure;
|
|
546
568
|
private isGracefulDegradationEnabled;
|
|
547
569
|
private recordCircuitFailure;
|
|
548
570
|
private isNegativeStoredValue;
|
|
549
571
|
private emitError;
|
|
550
572
|
private serializeKeyPart;
|
|
551
573
|
private isCacheSnapshotEntries;
|
|
574
|
+
private sanitizeSnapshotValue;
|
|
575
|
+
private validateSnapshotFilePath;
|
|
552
576
|
private normalizeForSerialization;
|
|
553
577
|
}
|
|
554
578
|
|