layercache 2.0.0 → 3.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/dist/index.d.cts CHANGED
@@ -1,12 +1,45 @@
1
- import { I as InvalidationBus, C as CacheLogger, a as InvalidationMessage, b as CacheTagIndex, c as CacheStack, d as CacheWrapOptions, e as CacheGetOptions, f as CacheLayer, g as CacheSerializer, h as CacheLayerSetManyEntry, i as CacheSingleFlightCoordinator, j as CacheSingleFlightExecutionOptions } from './edge-D2FpRlyS.cjs';
2
- export { k as CacheAdaptiveTtlOptions, l as CacheCircuitBreakerOptions, m as CacheContextOptionsContext, n as CacheDegradationOptions, o as CacheEntryWriteKind, p as CacheEntryWriteOptions, q as CacheFetcher, r as CacheFetcherContext, s as CacheHealthCheckResult, t as CacheHitRateSnapshot, u as CacheInspectResult, v as CacheLayerLatency, w as CacheMGetEntry, x as CacheMSetEntry, y as CacheMetricsSnapshot, z as CacheMissError, A as CacheNamespace, B as CacheRateLimitOptions, D as CacheSnapshotEntry, E as CacheStackEvents, F as CacheStackOptions, G as CacheStatsSnapshot, H as CacheTtlPolicy, J as CacheTtlPolicyContext, K as CacheWarmEntry, L as CacheWarmOptions, M as CacheWarmProgress, N as CacheWriteBehindOptions, O as CacheWriteOptions, P as EvictionPolicy, Q as LayerTtlMap, R as MemoryLayer, S as MemoryLayerOptions, T as MemoryLayerSnapshotEntry, U as PatternMatcher, V as TagIndex, W as createHonoCacheMiddleware } from './edge-D2FpRlyS.cjs';
1
+ import { I as InvalidationBus, C as CacheLogger, a as InvalidationMessage, b as CacheTagIndex, c as CacheStack, d as CacheWrapOptions, e as CacheGetOptions, f as CacheLayer, g as CacheSerializer, h as CacheLayerSetManyEntry, i as CacheSingleFlightCoordinator, j as CacheSingleFlightExecutionOptions } from './edge-BDyuPmIq.cjs';
2
+ export { k as CacheAdaptiveTtlOptions, l as CacheCircuitBreakerOptions, m as CacheContextOptionsContext, n as CacheDegradationOptions, o as CacheEntryWriteKind, p as CacheEntryWriteOptions, q as CacheFetcher, r as CacheFetcherContext, s as CacheHealthCheckResult, t as CacheHitRateSnapshot, u as CacheInspectResult, v as CacheLayerLatency, w as CacheMGetEntry, x as CacheMSetEntry, y as CacheMetricsSnapshot, z as CacheMissError, A as CacheNamespace, B as CacheRateLimitOptions, D as CacheSnapshotEntry, E as CacheStackEvents, F as CacheStackOptions, G as CacheStatsSnapshot, H as CacheTtlPolicy, J as CacheTtlPolicyContext, K as CacheWarmEntry, L as CacheWarmOptions, M as CacheWarmProgress, N as CacheWriteBehindOptions, O as CacheWriteOptions, P as EvictionPolicy, Q as LayerTtlMap, R as MemoryLayer, S as MemoryLayerOptions, T as MemoryLayerSnapshotEntry, U as PatternMatcher, V as TagIndex, W as createHonoCacheMiddleware } from './edge-BDyuPmIq.cjs';
3
3
  import Redis from 'ioredis';
4
4
  import 'node:events';
5
5
 
6
+ interface RedisGenerationClient {
7
+ get(key: string): Promise<string | null>;
8
+ set(key: string, value: string, mode?: 'NX'): Promise<unknown>;
9
+ incr(key: string): Promise<number>;
10
+ }
11
+ interface RedisGenerationStoreOptions {
12
+ /** Redis client used to persist and atomically bump the generation. */
13
+ client: RedisGenerationClient;
14
+ /** Redis key storing the active generation. Defaults to `layercache:generation`. */
15
+ key?: string;
16
+ }
17
+ declare class RedisGenerationStore {
18
+ private readonly client;
19
+ private readonly key;
20
+ constructor(options: RedisGenerationStoreOptions);
21
+ get(): Promise<number | undefined>;
22
+ getOrInitialize(initialGeneration?: number): Promise<number>;
23
+ set(generation: number): Promise<void>;
24
+ bump(): Promise<number>;
25
+ private parseGeneration;
26
+ private assertGeneration;
27
+ private isGeneration;
28
+ }
29
+
6
30
  interface RedisInvalidationBusOptions {
31
+ /** Redis client used to publish invalidation messages. */
7
32
  publisher: Redis;
33
+ /** Redis client used for subscriptions. Defaults to `publisher.duplicate()`. */
8
34
  subscriber?: Redis;
35
+ /** Pub/sub channel name. Defaults to `layercache:invalidation`. */
9
36
  channel?: string;
37
+ /**
38
+ * Optional shared secret used to sign and verify invalidation messages.
39
+ * When configured, unsigned or invalidly signed messages are rejected.
40
+ */
41
+ signingSecret?: string | Buffer;
42
+ /** Optional logger for invalid payloads or subscriber errors. */
10
43
  logger?: CacheLogger;
11
44
  }
12
45
  /**
@@ -21,43 +54,101 @@ declare class RedisInvalidationBus implements InvalidationBus {
21
54
  private readonly publisher;
22
55
  private readonly subscriber;
23
56
  private readonly logger?;
57
+ private readonly signingKey?;
24
58
  private readonly handlers;
25
59
  private sharedListener?;
26
60
  private subscribePromise;
27
61
  constructor(options: RedisInvalidationBusOptions);
62
+ /**
63
+ * Subscribes to invalidation messages and returns an unsubscribe function.
64
+ */
28
65
  subscribe(handler: (message: InvalidationMessage) => Promise<void> | void): Promise<() => Promise<void>>;
66
+ /**
67
+ * Publishes an invalidation message to other subscribers.
68
+ */
29
69
  publish(message: InvalidationMessage): Promise<void>;
30
70
  private dispatchToHandlers;
31
71
  private isInvalidationMessage;
72
+ private signMessage;
73
+ private verifySignedEnvelope;
74
+ private createSignature;
32
75
  private reportError;
33
76
  }
34
77
 
35
78
  interface RedisTagIndexOptions {
79
+ /** Redis client used for tag and known-key sets. */
36
80
  client: Redis;
81
+ /** Redis key prefix for index data. Defaults to `layercache:tag-index`. */
37
82
  prefix?: string;
83
+ /** Redis SCAN count hint used by pattern and prefix discovery. Defaults to 100. */
38
84
  scanCount?: number;
85
+ /** Number of shards for known-key sets. Defaults to 16. */
39
86
  knownKeysShards?: number;
87
+ /** Optional logger for legacy index warnings. */
88
+ logger?: CacheLogger;
89
+ }
90
+ interface RedisTagIndexMigrationResult {
91
+ migratedKeys: number;
40
92
  }
41
93
  declare class RedisTagIndex implements CacheTagIndex {
42
94
  private readonly client;
43
95
  private readonly prefix;
44
96
  private readonly scanCount;
45
97
  private readonly knownKeysShards;
98
+ private readonly logger?;
99
+ private warnedLegacyKnownKeys;
46
100
  constructor(options: RedisTagIndexOptions);
101
+ /**
102
+ * Records a key as known without changing tag assignments.
103
+ */
47
104
  touch(key: string): Promise<void>;
105
+ /**
106
+ * Replaces the tags associated with a key and records the key as known.
107
+ */
48
108
  track(key: string, tags: string[]): Promise<void>;
109
+ /**
110
+ * Removes a key from all tag mappings and known-key tracking.
111
+ */
49
112
  remove(key: string): Promise<void>;
113
+ /**
114
+ * Returns keys currently associated with a tag.
115
+ */
50
116
  keysForTag(tag: string): Promise<string[]>;
117
+ /**
118
+ * Visits keys currently associated with a tag.
119
+ */
51
120
  forEachKeyForTag(tag: string, visitor: (key: string) => void | Promise<void>): Promise<void>;
121
+ /**
122
+ * Returns known keys that start with a prefix.
123
+ */
52
124
  keysForPrefix(prefix: string): Promise<string[]>;
125
+ /**
126
+ * Visits known keys that start with a prefix.
127
+ */
53
128
  forEachKeyForPrefix(prefix: string, visitor: (key: string) => void | Promise<void>): Promise<void>;
129
+ /**
130
+ * Returns the tags currently associated with a key.
131
+ */
54
132
  tagsForKey(key: string): Promise<string[]>;
133
+ /**
134
+ * Returns known keys matching a wildcard pattern.
135
+ */
55
136
  matchPattern(pattern: string): Promise<string[]>;
137
+ /**
138
+ * Visits known keys matching a wildcard pattern.
139
+ */
56
140
  forEachKeyMatchingPattern(pattern: string, visitor: (key: string) => void | Promise<void>): Promise<void>;
141
+ /**
142
+ * Clears all Redis tag-index state under this prefix.
143
+ */
57
144
  clear(): Promise<void>;
145
+ migrateLegacyKnownKeys(): Promise<RedisTagIndexMigrationResult>;
58
146
  private scanIndexKeys;
59
147
  private knownKeysKeyFor;
148
+ private knownKeysKeysForRead;
60
149
  private knownKeysKeys;
150
+ private legacyKnownKeysKey;
151
+ private warnLegacyKnownKeys;
61
152
  private keyTagsKey;
62
153
  private tagKeysKey;
63
154
  }
@@ -69,9 +160,14 @@ interface CacheStatsHandlerOptions {
69
160
  * future release.
70
161
  */
71
162
  allowPublicAccess?: boolean;
163
+ /** Authorize requests before returning cache stats. Required unless `allowPublicAccess` is true. */
72
164
  authorize?: (request: unknown) => boolean | Promise<boolean>;
165
+ /** Status code returned when a request is unauthorized. Defaults to 403. */
73
166
  unauthorizedStatusCode?: number;
74
167
  }
168
+ /**
169
+ * Creates a small Node HTTP handler that returns `cache.getStats()` as JSON.
170
+ */
75
171
  declare function createCacheStatsHandler(cache: CacheStack, options?: CacheStatsHandlerOptions): (request: unknown, response: {
76
172
  setHeader?: (name: string, value: string) => void;
77
173
  end: (body: string) => void;
@@ -79,9 +175,14 @@ declare function createCacheStatsHandler(cache: CacheStack, options?: CacheStats
79
175
  }) => Promise<void>;
80
176
 
81
177
  interface CachedMethodDecoratorOptions<TArgs extends unknown[]> extends CacheWrapOptions<TArgs> {
178
+ /** Returns the CacheStack instance used for the decorated object instance. */
82
179
  cache: (instance: unknown) => CacheStack;
180
+ /** Cache key prefix for the method. Defaults to the decorated property name. */
83
181
  prefix?: string;
84
182
  }
183
+ /**
184
+ * Creates a method decorator that caches async method results per instance.
185
+ */
85
186
  declare function createCachedMethodDecorator<TArgs extends unknown[] = unknown[]>(options: CachedMethodDecoratorOptions<TArgs>): MethodDecorator;
86
187
 
87
188
  interface FastifyLike {
@@ -94,7 +195,9 @@ interface FastifyLikeReply {
94
195
  statusCode?: number;
95
196
  }
96
197
  interface FastifyLayercachePluginOptions {
198
+ /** Register an HTTP route that returns `cache.getStats()`. Disabled by default. */
97
199
  exposeStatsRoute?: boolean;
200
+ /** Path for the stats route when `exposeStatsRoute` is enabled. Defaults to `/cache/stats`. */
98
201
  statsPath?: string;
99
202
  /**
100
203
  * @deprecated Exposing cache stats without authentication is a security risk.
@@ -102,9 +205,14 @@ interface FastifyLayercachePluginOptions {
102
205
  * removed in a future release.
103
206
  */
104
207
  allowPublicStatsRoute?: boolean;
208
+ /** Authorize requests to the stats route. Required unless `allowPublicStatsRoute` is true. */
105
209
  authorizeStatsRoute?: (request: unknown) => boolean | Promise<boolean>;
210
+ /** Status code returned when a stats route request is unauthorized. Defaults to 403. */
106
211
  unauthorizedStatusCode?: number;
107
212
  }
213
+ /**
214
+ * Fastify plugin that decorates the server with `cache` and can expose a protected stats route.
215
+ */
108
216
  declare function createFastifyLayercachePlugin(cache: CacheStack, options?: FastifyLayercachePluginOptions): (fastify: FastifyLike) => Promise<void>;
109
217
 
110
218
  interface ExpressLikeRequest {
@@ -154,9 +262,14 @@ interface ExpressCacheMiddlewareOptions extends CacheGetOptions {
154
262
  declare function createExpressCacheMiddleware(cache: CacheStack, options?: ExpressCacheMiddlewareOptions): (req: ExpressLikeRequest, res: ExpressLikeResponse, next: NextFunction) => Promise<void>;
155
263
 
156
264
  interface GraphqlCacheOptions<TArgs extends unknown[]> extends CacheGetOptions {
265
+ /** Converts resolver arguments into a stable cache key suffix. */
157
266
  keyResolver?: (...args: TArgs) => string;
267
+ /** Allow fallback key generation from resolver args when no `keyResolver` is provided. */
158
268
  allowImplicitContextCaching?: boolean;
159
269
  }
270
+ /**
271
+ * Wraps a GraphQL resolver with read-through caching.
272
+ */
160
273
  declare function cacheGraphqlResolver<TArgs extends unknown[], TResult>(cache: CacheStack, prefix: string, resolver: (...args: TArgs) => Promise<TResult>, options?: GraphqlCacheOptions<TArgs>): (...args: TArgs) => Promise<TResult | null>;
161
274
 
162
275
  interface OpenTelemetrySpan {
@@ -180,18 +293,27 @@ declare function createOpenTelemetryPlugin(cache: CacheStack, tracer: OpenTeleme
180
293
  };
181
294
 
182
295
  interface TrpcCacheMiddlewareContext<TInput = unknown, TResult = unknown> {
296
+ /** Procedure path, when supplied by the adapter. */
183
297
  path?: string;
298
+ /** Procedure type, such as query or mutation. */
184
299
  type?: string;
300
+ /** Raw procedure input used by the key resolver. */
185
301
  rawInput?: TInput;
302
+ /** Runs the next tRPC middleware or resolver. */
186
303
  next: () => Promise<{
187
304
  ok: boolean;
188
305
  data?: TResult;
189
306
  }>;
190
307
  }
191
308
  interface TrpcCacheMiddlewareOptions<TInput> extends CacheGetOptions {
309
+ /** Converts procedure input and metadata into a stable cache key suffix. */
192
310
  keyResolver?: (input: TInput, path?: string, type?: string) => string;
311
+ /** Allow fallback key generation from procedure path and raw input. */
193
312
  allowImplicitContextCaching?: boolean;
194
313
  }
314
+ /**
315
+ * Creates a tRPC middleware that caches successful procedure results.
316
+ */
195
317
  declare function createTrpcCacheMiddleware<TInput = unknown, TResult = unknown>(cache: CacheStack, prefix: string, options?: TrpcCacheMiddlewareOptions<TInput>): (context: TrpcCacheMiddlewareContext<TInput, TResult>) => Promise<{
196
318
  ok: boolean;
197
319
  data?: TResult;
@@ -199,14 +321,23 @@ declare function createTrpcCacheMiddleware<TInput = unknown, TResult = unknown>(
199
321
 
200
322
  type CompressionAlgorithm = 'gzip' | 'brotli';
201
323
  interface RedisLayerOptions {
324
+ /** ioredis client used for all Redis commands. */
202
325
  client: Redis;
326
+ /** Default TTL in milliseconds for writes that do not provide an explicit TTL. */
203
327
  ttl?: number;
328
+ /** Layer name used for metrics and per-layer TTL maps. Defaults to `redis`. */
204
329
  name?: string;
330
+ /** Serializer or serializer chain used to encode values before storage. */
205
331
  serializer?: CacheSerializer | CacheSerializer[];
332
+ /** Prefix prepended to every Redis key. */
206
333
  prefix?: string;
334
+ /** Allow `clear()` without a key prefix. Disabled by default to avoid deleting unrelated Redis keys. */
207
335
  allowUnprefixedClear?: boolean;
336
+ /** Redis SCAN count hint used when discovering keys. Defaults to 100. */
208
337
  scanCount?: number;
338
+ /** Optional compression algorithm applied to large serialized payloads. */
209
339
  compression?: CompressionAlgorithm;
340
+ /** Minimum serialized payload size in bytes before compression is attempted. Defaults to 1 KiB. */
210
341
  compressionThreshold?: number;
211
342
  /**
212
343
  * Maximum number of bytes allowed after decompression.
@@ -218,8 +349,12 @@ interface RedisLayerOptions {
218
349
  * Slow commands reject so CacheStack can treat the layer as degraded.
219
350
  */
220
351
  commandTimeoutMs?: number;
352
+ /** Disconnect the Redis client when this layer is disposed. Disabled by default. */
221
353
  disconnectOnDispose?: boolean;
222
354
  }
355
+ /**
356
+ * Redis-backed cache layer for shared cross-process cache state.
357
+ */
223
358
  declare class RedisLayer implements CacheLayer {
224
359
  readonly name: string;
225
360
  readonly defaultTtl?: number;
@@ -234,25 +369,70 @@ declare class RedisLayer implements CacheLayer {
234
369
  private readonly decompressionMaxBytes;
235
370
  private readonly commandTimeoutMs;
236
371
  private readonly disconnectOnDispose;
372
+ /**
373
+ * Creates a Redis cache layer using an existing ioredis client.
374
+ */
237
375
  constructor(options: RedisLayerOptions);
376
+ /**
377
+ * Reads and unwraps a fresh value from Redis.
378
+ */
238
379
  get<T>(key: string): Promise<T | null>;
380
+ /**
381
+ * Reads the raw stored value or envelope from Redis.
382
+ */
239
383
  getEntry<T = unknown>(key: string): Promise<T | null>;
384
+ /**
385
+ * Reads many raw entries from Redis using a pipeline.
386
+ */
240
387
  getMany<T>(keys: string[]): Promise<Array<T | null>>;
388
+ /**
389
+ * Writes many entries to Redis using a pipeline.
390
+ */
241
391
  setMany(entries: CacheLayerSetManyEntry[]): Promise<void>;
392
+ /**
393
+ * Stores a value in Redis using the provided TTL or layer default TTL.
394
+ */
242
395
  set(key: string, value: unknown, ttl?: number | undefined): Promise<void>;
396
+ /**
397
+ * Deletes a key from Redis.
398
+ */
243
399
  delete(key: string): Promise<void>;
400
+ /**
401
+ * Deletes multiple keys from Redis in batches.
402
+ */
244
403
  deleteMany(keys: string[]): Promise<void>;
404
+ /**
405
+ * Returns true when the key exists in Redis.
406
+ */
245
407
  has(key: string): Promise<boolean>;
408
+ /**
409
+ * Returns remaining Redis TTL in milliseconds, or null when absent or non-expiring.
410
+ */
246
411
  ttl(key: string): Promise<number | null>;
412
+ /**
413
+ * Returns the number of keys under this layer's prefix.
414
+ */
247
415
  size(): Promise<number>;
416
+ /**
417
+ * Runs a Redis ping command.
418
+ */
248
419
  ping(): Promise<boolean>;
420
+ /**
421
+ * Disconnects the Redis client when `disconnectOnDispose` is enabled.
422
+ */
249
423
  dispose(): Promise<void>;
250
424
  /**
251
425
  * Deletes all keys matching the layer's prefix in batches to avoid
252
426
  * loading millions of keys into memory at once.
253
427
  */
254
428
  clear(): Promise<void>;
429
+ /**
430
+ * Returns keys under this layer's prefix without the prefix included.
431
+ */
255
432
  keys(): Promise<string[]>;
433
+ /**
434
+ * Visits keys under this layer's prefix without materializing all results.
435
+ */
256
436
  forEachKey(visitor: (key: string) => void | Promise<void>): Promise<void>;
257
437
  private scanKeys;
258
438
  private withPrefix;
@@ -279,9 +459,13 @@ declare class RedisLayer implements CacheLayer {
279
459
  }
280
460
 
281
461
  interface DiskLayerOptions {
462
+ /** Directory where cache entry files are stored. */
282
463
  directory: string;
464
+ /** Default TTL in milliseconds for writes that do not provide an explicit TTL. */
283
465
  ttl?: number;
466
+ /** Layer name used for metrics and per-layer TTL maps. Defaults to `disk`. */
284
467
  name?: string;
468
+ /** Serializer used to encode values before writing them to disk. */
285
469
  serializer?: CacheSerializer;
286
470
  /**
287
471
  * Maximum number of cache files to store on disk. When exceeded, the oldest
@@ -331,25 +515,70 @@ declare class DiskLayer implements CacheLayer {
331
515
  private readonly maxEntryBytes;
332
516
  private readonly protection;
333
517
  private writeQueue;
518
+ /**
519
+ * Creates a disk-backed cache layer.
520
+ */
334
521
  constructor(options: DiskLayerOptions);
522
+ /**
523
+ * Reads and unwraps a fresh value from disk.
524
+ */
335
525
  get<T>(key: string): Promise<T | null>;
526
+ /**
527
+ * Reads the raw stored value or envelope from disk.
528
+ */
336
529
  getEntry<T = unknown>(key: string): Promise<T | null>;
530
+ /**
531
+ * Stores a value on disk using the provided TTL or layer default TTL.
532
+ */
337
533
  set(key: string, value: unknown, ttl?: number | undefined): Promise<void>;
534
+ /**
535
+ * Reads many raw entries from disk.
536
+ */
338
537
  getMany<T>(keys: string[]): Promise<Array<T | null>>;
538
+ /**
539
+ * Writes many entries to disk.
540
+ */
339
541
  setMany(entries: CacheLayerSetManyEntry[]): Promise<void>;
542
+ /**
543
+ * Returns true when the key exists and has not expired.
544
+ */
340
545
  has(key: string): Promise<boolean>;
546
+ /**
547
+ * Returns remaining TTL in milliseconds, or null when absent or non-expiring.
548
+ */
341
549
  ttl(key: string): Promise<number | null>;
550
+ /**
551
+ * Deletes a key from disk.
552
+ */
342
553
  delete(key: string): Promise<void>;
554
+ /**
555
+ * Deletes multiple keys from disk.
556
+ */
343
557
  deleteMany(keys: string[]): Promise<void>;
558
+ /**
559
+ * Removes all cache entry files from this layer's directory.
560
+ */
344
561
  clear(): Promise<void>;
345
562
  /**
346
563
  * Returns the original cache key strings stored on disk.
347
564
  * Expired entries are skipped and cleaned up during the scan.
348
565
  */
349
566
  keys(): Promise<string[]>;
567
+ /**
568
+ * Visits all non-expired keys stored on disk.
569
+ */
350
570
  forEachKey(visitor: (key: string) => void | Promise<void>): Promise<void>;
571
+ /**
572
+ * Returns the number of non-expired entries stored on disk.
573
+ */
351
574
  size(): Promise<number>;
575
+ /**
576
+ * Verifies the cache directory can be created.
577
+ */
352
578
  ping(): Promise<boolean>;
579
+ /**
580
+ * Reserved for interface compatibility; DiskLayer does not hold persistent handles.
581
+ */
353
582
  dispose(): Promise<void>;
354
583
  private keyToPath;
355
584
  private resolveDirectory;
@@ -377,19 +606,27 @@ declare class DiskLayer implements CacheLayer {
377
606
  * npm install memcache-client
378
607
  */
379
608
  interface MemcachedClient {
609
+ /** Read a raw value for `key`, returning null on miss. */
380
610
  get(key: string): Promise<{
381
611
  value: Buffer | null;
382
612
  } | null>;
613
+ /** Store a raw value with optional expiration in seconds. */
383
614
  set(key: string, value: string | Buffer, options?: {
384
615
  expires?: number;
385
616
  }): Promise<boolean | undefined>;
617
+ /** Delete a raw key. */
386
618
  delete(key: string): Promise<boolean | undefined>;
387
619
  }
388
620
  interface MemcachedLayerOptions {
621
+ /** Memcached-compatible client implementation. */
389
622
  client: MemcachedClient;
623
+ /** Default TTL in milliseconds for writes that do not provide an explicit TTL. */
390
624
  ttl?: number;
625
+ /** Layer name used for metrics and per-layer TTL maps. Defaults to `memcached`. */
391
626
  name?: string;
627
+ /** Prefix prepended to every Memcached key. */
392
628
  keyPrefix?: string;
629
+ /** Serializer used to encode values before storing them in Memcached. */
393
630
  serializer?: CacheSerializer;
394
631
  }
395
632
  /**
@@ -417,32 +654,74 @@ declare class MemcachedLayer implements CacheLayer {
417
654
  private readonly client;
418
655
  private readonly keyPrefix;
419
656
  private readonly serializer;
657
+ /**
658
+ * Creates a Memcached cache layer using a compatible client.
659
+ */
420
660
  constructor(options: MemcachedLayerOptions);
661
+ /**
662
+ * Reads and unwraps a fresh value from Memcached.
663
+ */
421
664
  get<T>(key: string): Promise<T | null>;
665
+ /**
666
+ * Reads the raw stored value or envelope from Memcached.
667
+ */
422
668
  getEntry<T = unknown>(key: string): Promise<T | null>;
669
+ /**
670
+ * Reads many raw entries from Memcached.
671
+ */
423
672
  getMany<T>(keys: string[]): Promise<Array<T | null>>;
673
+ /**
674
+ * Stores a value in Memcached using the provided TTL or layer default TTL.
675
+ */
424
676
  set(key: string, value: unknown, ttl?: number | undefined): Promise<void>;
677
+ /**
678
+ * Returns true when the key exists in Memcached.
679
+ */
425
680
  has(key: string): Promise<boolean>;
681
+ /**
682
+ * Deletes a key from Memcached.
683
+ */
426
684
  delete(key: string): Promise<void>;
685
+ /**
686
+ * Deletes multiple keys from Memcached.
687
+ */
427
688
  deleteMany(keys: string[]): Promise<void>;
689
+ /**
690
+ * Always throws because Memcached has no safe prefix clear primitive.
691
+ */
428
692
  clear(): Promise<void>;
429
693
  private withPrefix;
430
694
  private validateKey;
431
695
  }
432
696
 
433
697
  declare class JsonSerializer implements CacheSerializer {
698
+ /**
699
+ * Serializes a value to JSON.
700
+ */
434
701
  serialize(value: unknown): string;
702
+ /**
703
+ * Parses JSON and sanitizes the result before returning it.
704
+ */
435
705
  deserialize<T>(payload: string | Buffer): T;
436
706
  }
437
707
 
438
708
  declare class MsgpackSerializer implements CacheSerializer {
709
+ /**
710
+ * Serializes a value to MessagePack bytes.
711
+ */
439
712
  serialize(value: unknown): Buffer;
713
+ /**
714
+ * Decodes MessagePack bytes and sanitizes the result before returning it.
715
+ */
440
716
  deserialize<T>(payload: string | Buffer): T;
441
717
  }
442
718
 
443
719
  interface RedisSingleFlightCoordinatorOptions {
720
+ /** Redis client used for lock acquisition, renewal, and release. */
444
721
  client: Redis;
722
+ /** Redis key prefix for single-flight locks. Defaults to `layercache:singleflight`. */
445
723
  prefix?: string;
724
+ /** Per-command timeout in milliseconds for Redis operations. */
446
725
  commandTimeoutMs?: number;
447
726
  }
448
727
  declare class RedisSingleFlightCoordinator implements CacheSingleFlightCoordinator {
@@ -450,6 +729,10 @@ declare class RedisSingleFlightCoordinator implements CacheSingleFlightCoordinat
450
729
  private readonly prefix;
451
730
  private readonly commandTimeoutMs;
452
731
  constructor(options: RedisSingleFlightCoordinatorOptions);
732
+ /**
733
+ * Executes `worker` when this process acquires the Redis lock; otherwise runs
734
+ * `waiter` while another process owns the work.
735
+ */
453
736
  execute<T>(key: string, options: CacheSingleFlightExecutionOptions, worker: () => Promise<T>, waiter: () => Promise<T>): Promise<T>;
454
737
  private startLeaseRenewal;
455
738
  private normalizeCommandTimeoutMs;
@@ -475,6 +758,9 @@ declare class StampedeGuard {
475
758
  private readonly maxInFlight;
476
759
  private readonly entryTimeoutMs;
477
760
  constructor(options?: StampedeGuardOptions);
761
+ /**
762
+ * Deduplicates concurrent work for the same key in this process.
763
+ */
478
764
  execute<T>(key: string, task: () => Promise<T>): Promise<T>;
479
765
  private withTimeout;
480
766
  private releaseEntry;
@@ -504,4 +790,4 @@ declare function createPrometheusMetricsExporter(stacks: CacheStack | Array<{
504
790
  name: string;
505
791
  }>): () => string;
506
792
 
507
- export { CacheGetOptions, CacheLayer, CacheLayerSetManyEntry, CacheLogger, CacheSerializer, CacheSingleFlightCoordinator, CacheSingleFlightExecutionOptions, CacheStack, CacheTagIndex, CacheWrapOptions, DiskLayer, InvalidationBus, InvalidationMessage, JsonSerializer, type MemcachedClient, MemcachedLayer, MsgpackSerializer, RedisInvalidationBus, RedisLayer, RedisSingleFlightCoordinator, RedisTagIndex, StampedeGuard, cacheGraphqlResolver, createCacheStatsHandler, createCachedMethodDecorator, createExpressCacheMiddleware, createFastifyLayercachePlugin, createOpenTelemetryPlugin, createPrometheusMetricsExporter, createTrpcCacheMiddleware };
793
+ export { CacheGetOptions, CacheLayer, CacheLayerSetManyEntry, CacheLogger, CacheSerializer, CacheSingleFlightCoordinator, CacheSingleFlightExecutionOptions, CacheStack, CacheTagIndex, CacheWrapOptions, DiskLayer, InvalidationBus, InvalidationMessage, JsonSerializer, type MemcachedClient, MemcachedLayer, MsgpackSerializer, RedisGenerationStore, RedisInvalidationBus, RedisLayer, RedisSingleFlightCoordinator, RedisTagIndex, StampedeGuard, cacheGraphqlResolver, createCacheStatsHandler, createCachedMethodDecorator, createExpressCacheMiddleware, createFastifyLayercachePlugin, createOpenTelemetryPlugin, createPrometheusMetricsExporter, createTrpcCacheMiddleware };