@tachybase/module-workflow 1.1.14 → 1.1.15

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.
@@ -2,15 +2,20 @@
2
2
  * @module LRUCache
3
3
  */
4
4
  declare const TYPE: unique symbol;
5
- type Index = number & {
5
+ export type PosInt = number & {
6
+ [TYPE]: 'Positive Integer';
7
+ };
8
+ export type Index = number & {
6
9
  [TYPE]: 'LRUCache Index';
7
10
  };
8
- type UintArray = Uint8Array | Uint16Array | Uint32Array;
9
- type NumberArray = UintArray | number[];
11
+ export type UintArray = Uint8Array | Uint16Array | Uint32Array;
12
+ export type NumberArray = UintArray | number[];
10
13
  declare class ZeroArray extends Array<number> {
11
14
  constructor(size: number);
12
15
  }
13
- type StackLike = Stack | Index[];
16
+ export type { ZeroArray };
17
+ export type { Stack };
18
+ export type StackLike = Stack | Index[];
14
19
  declare class Stack {
15
20
  #private;
16
21
  heap: NumberArray;
@@ -25,11 +30,16 @@ declare class Stack {
25
30
  /**
26
31
  * Promise representing an in-progress {@link LRUCache#fetch} call
27
32
  */
28
- export type BackgroundFetch<V> = Promise<V | undefined | void> & {
33
+ export type BackgroundFetch<V> = Promise<V | undefined> & {
29
34
  __returned: BackgroundFetch<V> | undefined;
30
35
  __abortController: AbortController;
31
36
  __staleWhileFetching: V | undefined;
32
37
  };
38
+ export type DisposeTask<K, V> = [
39
+ value: V,
40
+ key: K,
41
+ reason: LRUCache.DisposeReason
42
+ ];
33
43
  export declare namespace LRUCache {
34
44
  /**
35
45
  * An integer greater than 0, reflecting the calculated size of items
@@ -47,14 +57,38 @@ export declare namespace LRUCache {
47
57
  /**
48
58
  * The reason why an item was removed from the cache, passed
49
59
  * to the {@link Disposer} methods.
50
- */
51
- type DisposeReason = 'evict' | 'set' | 'delete';
60
+ *
61
+ * - `evict`: The item was evicted because it is the least recently used,
62
+ * and the cache is full.
63
+ * - `set`: A new value was set, overwriting the old value being disposed.
64
+ * - `delete`: The item was explicitly deleted, either by calling
65
+ * {@link LRUCache#delete}, {@link LRUCache#clear}, or
66
+ * {@link LRUCache#set} with an undefined value.
67
+ * - `expire`: The item was removed due to exceeding its TTL.
68
+ * - `fetch`: A {@link OptionsBase#fetchMethod} operation returned
69
+ * `undefined` or was aborted, causing the item to be deleted.
70
+ */
71
+ type DisposeReason = 'evict' | 'set' | 'delete' | 'expire' | 'fetch';
52
72
  /**
53
73
  * A method called upon item removal, passed as the
54
74
  * {@link OptionsBase.dispose} and/or
55
75
  * {@link OptionsBase.disposeAfter} options.
56
76
  */
57
77
  type Disposer<K, V> = (value: V, key: K, reason: DisposeReason) => void;
78
+ /**
79
+ * The reason why an item was added to the cache, passed
80
+ * to the {@link Inserter} methods.
81
+ *
82
+ * - `add`: the item was not found in the cache, and was added
83
+ * - `update`: the item was in the cache, with the same value provided
84
+ * - `replace`: the item was in the cache, and replaced
85
+ */
86
+ type InsertReason = 'add' | 'update' | 'replace';
87
+ /**
88
+ * A method called upon item insertion, passed as the
89
+ * {@link OptionsBase.insert}
90
+ */
91
+ type Inserter<K, V> = (value: V, key: K, reason: InsertReason) => void;
58
92
  /**
59
93
  * A function that returns the effective calculated size
60
94
  * of an entry in the cache.
@@ -74,8 +108,14 @@ export declare namespace LRUCache {
74
108
  context: FC;
75
109
  }
76
110
  /**
77
- * Status object that may be passed to {@link LRUCache#fetch},
78
- * {@link LRUCache#get}, {@link LRUCache#set}, and {@link LRUCache#has}.
111
+ * Occasionally, it may be useful to track the internal behavior of the
112
+ * cache, particularly for logging, debugging, or for behavior within the
113
+ * `fetchMethod`. To do this, you can pass a `status` object to the
114
+ * {@link LRUCache#fetch}, {@link LRUCache#get}, {@link LRUCache#set},
115
+ * {@link LRUCache#memo}, and {@link LRUCache#has} methods.
116
+ *
117
+ * The `status` option should be a plain JavaScript object. The following
118
+ * fields will be set on it appropriately, depending on the situation.
79
119
  */
80
120
  interface Status<V> {
81
121
  /**
@@ -135,7 +175,8 @@ export declare namespace LRUCache {
135
175
  * various states.
136
176
  *
137
177
  * - inflight: there is another fetch() for this key which is in process
138
- * - get: there is no fetchMethod, so {@link LRUCache#get} was called.
178
+ * - get: there is no {@link OptionsBase.fetchMethod}, so
179
+ * {@link LRUCache#get} was called.
139
180
  * - miss: the item is not in cache, and will be fetched.
140
181
  * - hit: the item is in the cache, and was resolved immediately.
141
182
  * - stale: the item is in the cache, but stale.
@@ -198,7 +239,7 @@ export declare namespace LRUCache {
198
239
  * {@link OptionsBase.noDeleteOnFetchRejection},
199
240
  * {@link OptionsBase.allowStaleOnFetchRejection},
200
241
  * {@link FetchOptions.forceRefresh}, and
201
- * {@link OptionsBase.context}
242
+ * {@link FetcherOptions.context}
202
243
  *
203
244
  * Any of these may be modified in the {@link OptionsBase.fetchMethod}
204
245
  * function, but the {@link GetOptions} fields will of course have no
@@ -241,9 +282,70 @@ export declare namespace LRUCache {
241
282
  * Options provided to {@link LRUCache#fetch} when the FC type is
242
283
  * `undefined` or `void`
243
284
  */
244
- interface FetchOptionsNoContext<K, V, FC> extends FetchOptions<K, V, FC> {
285
+ interface FetchOptionsNoContext<K, V> extends FetchOptions<K, V, undefined> {
286
+ context?: undefined;
287
+ }
288
+ interface MemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL' | 'noDeleteOnFetchRejection' | 'allowStaleOnFetchRejection' | 'ignoreFetchAbort' | 'allowStaleOnFetchAbort'> {
289
+ /**
290
+ * Set to true to force a re-load of the existing data, even if it
291
+ * is not yet stale.
292
+ */
293
+ forceRefresh?: boolean;
294
+ /**
295
+ * Context provided to the {@link OptionsBase.memoMethod} as
296
+ * the {@link MemoizerOptions.context} param.
297
+ *
298
+ * If the FC type is specified as unknown (the default),
299
+ * undefined or void, then this is optional. Otherwise, it will
300
+ * be required.
301
+ */
302
+ context?: FC;
303
+ status?: Status<V>;
304
+ }
305
+ /**
306
+ * Options provided to {@link LRUCache#memo} when the FC type is something
307
+ * other than `unknown`, `undefined`, or `void`
308
+ */
309
+ interface MemoOptionsWithContext<K, V, FC> extends MemoOptions<K, V, FC> {
310
+ context: FC;
311
+ }
312
+ /**
313
+ * Options provided to {@link LRUCache#memo} when the FC type is
314
+ * `undefined` or `void`
315
+ */
316
+ interface MemoOptionsNoContext<K, V> extends MemoOptions<K, V, undefined> {
245
317
  context?: undefined;
246
318
  }
319
+ /**
320
+ * Options provided to the
321
+ * {@link OptionsBase.memoMethod} function.
322
+ */
323
+ interface MemoizerOptions<K, V, FC = unknown> {
324
+ options: MemoizerMemoOptions<K, V, FC>;
325
+ /**
326
+ * Object provided in the {@link MemoOptions.context} option to
327
+ * {@link LRUCache#memo}
328
+ */
329
+ context: FC;
330
+ }
331
+ /**
332
+ * options which override the options set in the LRUCache constructor
333
+ * when calling {@link LRUCache#memo}.
334
+ *
335
+ * This is the union of {@link GetOptions} and {@link SetOptions}, plus
336
+ * {@link MemoOptions.forceRefresh}, and
337
+ * {@link MemoOptions.context}
338
+ *
339
+ * Any of these may be modified in the {@link OptionsBase.memoMethod}
340
+ * function, but the {@link GetOptions} fields will of course have no
341
+ * effect, as the {@link LRUCache#get} call already happened by the time
342
+ * the memoMethod is called.
343
+ */
344
+ interface MemoizerMemoOptions<K, V, FC = unknown> extends Pick<OptionsBase<K, V, FC>, 'allowStale' | 'updateAgeOnGet' | 'noDeleteOnStaleGet' | 'sizeCalculation' | 'ttl' | 'noDisposeOnSet' | 'noUpdateTTL'> {
345
+ status?: Status<V>;
346
+ size?: Size;
347
+ start?: Milliseconds;
348
+ }
247
349
  /**
248
350
  * Options that may be passed to the {@link LRUCache#has} method.
249
351
  */
@@ -285,7 +387,11 @@ export declare namespace LRUCache {
285
387
  /**
286
388
  * The type signature for the {@link OptionsBase.fetchMethod} option.
287
389
  */
288
- type Fetcher<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: FetcherOptions<K, V, FC>) => Promise<V | void | undefined> | V | void | undefined;
390
+ type Fetcher<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: FetcherOptions<K, V, FC>) => Promise<V | undefined | void> | V | undefined | void;
391
+ /**
392
+ * the type signature for the {@link OptionsBase.memoMethod} option.
393
+ */
394
+ type Memoizer<K, V, FC = unknown> = (key: K, staleValue: V | undefined, options: MemoizerOptions<K, V, FC>) => V;
289
395
  /**
290
396
  * Options which may be passed to the {@link LRUCache} constructor.
291
397
  *
@@ -300,6 +406,14 @@ export declare namespace LRUCache {
300
406
  * (and in fact required by the type definitions here) that the cache
301
407
  * also set {@link OptionsBase.ttlAutopurge}, to prevent potentially
302
408
  * unbounded storage.
409
+ *
410
+ * All options are also available on the {@link LRUCache} instance, making
411
+ * it safe to pass an LRUCache instance as the options argumemnt to
412
+ * make another empty cache of the same type.
413
+ *
414
+ * Some options are marked as read-only, because changing them after
415
+ * instantiation is not safe. Changing any of the other options will of
416
+ * course only have an effect on subsequent method calls.
303
417
  */
304
418
  interface OptionsBase<K, V, FC> {
305
419
  /**
@@ -313,20 +427,44 @@ export declare namespace LRUCache {
313
427
  * Note that significantly fewer items may be stored, if
314
428
  * {@link OptionsBase.maxSize} and/or {@link OptionsBase.ttl} are also
315
429
  * set.
430
+ *
431
+ * **It is strongly recommended to set a `max` to prevent unbounded growth
432
+ * of the cache.**
316
433
  */
317
434
  max?: Count;
318
435
  /**
319
436
  * Max time in milliseconds for items to live in cache before they are
320
- * considered stale. Note that stale items are NOT preemptively removed
321
- * by default, and MAY live in the cache long after they have expired.
437
+ * considered stale. Note that stale items are NOT preemptively removed by
438
+ * default, and MAY live in the cache, contributing to its LRU max, long
439
+ * after they have expired, unless {@link OptionsBase.ttlAutopurge} is
440
+ * set.
441
+ *
442
+ * If set to `0` (the default value), then that means "do not track
443
+ * TTL", not "expire immediately".
322
444
  *
323
445
  * Also, as this cache is optimized for LRU/MRU operations, some of
324
446
  * the staleness/TTL checks will reduce performance, as they will incur
325
447
  * overhead by deleting items.
326
448
  *
327
- * Must be an integer number of ms. If set to 0, this indicates "no TTL"
449
+ * This is not primarily a TTL cache, and does not make strong TTL
450
+ * guarantees. There is no pre-emptive pruning of expired items, but you
451
+ * _may_ set a TTL on the cache, and it will treat expired items as missing
452
+ * when they are fetched, and delete them.
453
+ *
454
+ * Optional, but must be a non-negative integer in ms if specified.
328
455
  *
329
- * @default 0
456
+ * This may be overridden by passing an options object to `cache.set()`.
457
+ *
458
+ * At least one of `max`, `maxSize`, or `TTL` is required. This must be a
459
+ * positive integer if set.
460
+ *
461
+ * Even if ttl tracking is enabled, **it is strongly recommended to set a
462
+ * `max` to prevent unbounded growth of the cache.**
463
+ *
464
+ * If ttl tracking is enabled, and `max` and `maxSize` are not set,
465
+ * and `ttlAutopurge` is not set, then a warning will be emitted
466
+ * cautioning about the potential for unbounded memory consumption.
467
+ * (The TypeScript definitions will also discourage this.)
330
468
  */
331
469
  ttl?: Milliseconds;
332
470
  /**
@@ -346,54 +484,106 @@ export declare namespace LRUCache {
346
484
  ttlResolution?: Milliseconds;
347
485
  /**
348
486
  * Preemptively remove stale items from the cache.
349
- * Note that this may significantly degrade performance,
350
- * especially if the cache is storing a large number of items.
351
- * It is almost always best to just leave the stale items in
352
- * the cache, and let them fall out as new items are added.
487
+ *
488
+ * Note that this may *significantly* degrade performance, especially if
489
+ * the cache is storing a large number of items. It is almost always best
490
+ * to just leave the stale items in the cache, and let them fall out as new
491
+ * items are added.
353
492
  *
354
493
  * Note that this means that {@link OptionsBase.allowStale} is a bit
355
494
  * pointless, as stale items will be deleted almost as soon as they
356
495
  * expire.
357
496
  *
358
- * @default false
497
+ * Use with caution!
359
498
  */
360
499
  ttlAutopurge?: boolean;
361
500
  /**
362
- * Update the age of items on {@link LRUCache#get}, renewing their TTL
501
+ * When using time-expiring entries with `ttl`, setting this to `true` will
502
+ * make each item's age reset to 0 whenever it is retrieved from cache with
503
+ * {@link LRUCache#get}, causing it to not expire. (It can still fall out
504
+ * of cache based on recency of use, of course.)
363
505
  *
364
506
  * Has no effect if {@link OptionsBase.ttl} is not set.
365
507
  *
366
- * @default false
508
+ * This may be overridden by passing an options object to `cache.get()`.
367
509
  */
368
510
  updateAgeOnGet?: boolean;
369
511
  /**
370
- * Update the age of items on {@link LRUCache#has}, renewing their TTL
512
+ * When using time-expiring entries with `ttl`, setting this to `true` will
513
+ * make each item's age reset to 0 whenever its presence in the cache is
514
+ * checked with {@link LRUCache#has}, causing it to not expire. (It can
515
+ * still fall out of cache based on recency of use, of course.)
371
516
  *
372
517
  * Has no effect if {@link OptionsBase.ttl} is not set.
373
- *
374
- * @default false
375
518
  */
376
519
  updateAgeOnHas?: boolean;
377
520
  /**
378
521
  * Allow {@link LRUCache#get} and {@link LRUCache#fetch} calls to return
379
522
  * stale data, if available.
523
+ *
524
+ * By default, if you set `ttl`, stale items will only be deleted from the
525
+ * cache when you `get(key)`. That is, it's not preemptively pruning items,
526
+ * unless {@link OptionsBase.ttlAutopurge} is set.
527
+ *
528
+ * If you set `allowStale:true`, it'll return the stale value *as well as*
529
+ * deleting it. If you don't set this, then it'll return `undefined` when
530
+ * you try to get a stale entry.
531
+ *
532
+ * Note that when a stale entry is fetched, _even if it is returned due to
533
+ * `allowStale` being set_, it is removed from the cache immediately. You
534
+ * can suppress this behavior by setting
535
+ * {@link OptionsBase.noDeleteOnStaleGet}, either in the constructor, or in
536
+ * the options provided to {@link LRUCache#get}.
537
+ *
538
+ * This may be overridden by passing an options object to `cache.get()`.
539
+ * The `cache.has()` method will always return `false` for stale items.
540
+ *
541
+ * Only relevant if a ttl is set.
380
542
  */
381
543
  allowStale?: boolean;
382
544
  /**
383
- * Function that is called on items when they are dropped from the cache.
384
- * This can be handy if you want to close file descriptors or do other
385
- * cleanup tasks when items are no longer accessible. Called with `key,
386
- * value`. It's called before actually removing the item from the
387
- * internal cache, so it is *NOT* safe to re-add them.
545
+ * Function that is called on items when they are dropped from the
546
+ * cache, as `dispose(value, key, reason)`.
388
547
  *
389
- * Use {@link OptionsBase.disposeAfter} if you wish to dispose items after
390
- * they have been full removed, when it is safe to add them back to the
391
- * cache.
548
+ * This can be handy if you want to close file descriptors or do
549
+ * other cleanup tasks when items are no longer stored in the cache.
550
+ *
551
+ * **NOTE**: It is called _before_ the item has been fully removed
552
+ * from the cache, so if you want to put it right back in, you need
553
+ * to wait until the next tick. If you try to add it back in during
554
+ * the `dispose()` function call, it will break things in subtle and
555
+ * weird ways.
556
+ *
557
+ * Unlike several other options, this may _not_ be overridden by
558
+ * passing an option to `set()`, for performance reasons.
559
+ *
560
+ * The `reason` will be one of the following strings, corresponding
561
+ * to the reason for the item's deletion:
562
+ *
563
+ * - `evict` Item was evicted to make space for a new addition
564
+ * - `set` Item was overwritten by a new value
565
+ * - `expire` Item expired its TTL
566
+ * - `fetch` Item was deleted due to a failed or aborted fetch, or a
567
+ * fetchMethod returning `undefined.
568
+ * - `delete` Item was removed by explicit `cache.delete(key)`,
569
+ * `cache.clear()`, or `cache.set(key, undefined)`.
392
570
  */
393
571
  dispose?: Disposer<K, V>;
572
+ /**
573
+ * Function that is called when new items are inserted into the cache,
574
+ * as `onInsert(value, key, reason)`.
575
+ *
576
+ * This can be useful if you need to perform actions when an item is
577
+ * added, such as logging or tracking insertions.
578
+ *
579
+ * Unlike some other options, this may _not_ be overridden by passing
580
+ * an option to `set()`, for performance and consistency reasons.
581
+ */
582
+ onInsert?: Inserter<K, V>;
394
583
  /**
395
584
  * The same as {@link OptionsBase.dispose}, but called *after* the entry
396
585
  * is completely removed and the cache is once again in a clean state.
586
+ *
397
587
  * It is safe to add an item right back into the cache at this point.
398
588
  * However, note that it is *very* easy to inadvertently create infinite
399
589
  * recursion this way.
@@ -403,26 +593,43 @@ export declare namespace LRUCache {
403
593
  * Set to true to suppress calling the
404
594
  * {@link OptionsBase.dispose} function if the entry key is
405
595
  * still accessible within the cache.
596
+ *
406
597
  * This may be overridden by passing an options object to
407
598
  * {@link LRUCache#set}.
599
+ *
600
+ * Only relevant if `dispose` or `disposeAfter` are set.
408
601
  */
409
602
  noDisposeOnSet?: boolean;
410
603
  /**
411
- * Boolean flag to tell the cache to not update the TTL when
412
- * setting a new value for an existing key (ie, when updating a value
413
- * rather than inserting a new value). Note that the TTL value is
414
- * _always_ set (if provided) when adding a new entry into the cache.
604
+ * Boolean flag to tell the cache to not update the TTL when setting a new
605
+ * value for an existing key (ie, when updating a value rather than
606
+ * inserting a new value). Note that the TTL value is _always_ set (if
607
+ * provided) when adding a new entry into the cache.
415
608
  *
416
609
  * Has no effect if a {@link OptionsBase.ttl} is not set.
610
+ *
611
+ * May be passed as an option to {@link LRUCache#set}.
417
612
  */
418
613
  noUpdateTTL?: boolean;
419
614
  /**
420
- * If you wish to track item size, you must provide a maxSize
421
- * note that we still will only keep up to max *actual items*,
422
- * if max is set, so size tracking may cause fewer than max items
423
- * to be stored. At the extreme, a single item of maxSize size
424
- * will cause everything else in the cache to be dropped when it
425
- * is added. Use with caution!
615
+ * Set to a positive integer to track the sizes of items added to the
616
+ * cache, and automatically evict items in order to stay below this size.
617
+ * Note that this may result in fewer than `max` items being stored.
618
+ *
619
+ * Attempting to add an item to the cache whose calculated size is greater
620
+ * that this amount will be a no-op. The item will not be cached, and no
621
+ * other items will be evicted.
622
+ *
623
+ * Optional, must be a positive integer if provided.
624
+ *
625
+ * Sets `maxEntrySize` to the same value, unless a different value is
626
+ * provided for `maxEntrySize`.
627
+ *
628
+ * At least one of `max`, `maxSize`, or `TTL` is required. This must be a
629
+ * positive integer if set.
630
+ *
631
+ * Even if size tracking is enabled, **it is strongly recommended to set a
632
+ * `max` to prevent unbounded growth of the cache.**
426
633
  *
427
634
  * Note also that size tracking can negatively impact performance,
428
635
  * though for most cases, only minimally.
@@ -432,13 +639,22 @@ export declare namespace LRUCache {
432
639
  * The maximum allowed size for any single item in the cache.
433
640
  *
434
641
  * If a larger item is passed to {@link LRUCache#set} or returned by a
435
- * {@link OptionsBase.fetchMethod}, then it will not be stored in the
436
- * cache.
642
+ * {@link OptionsBase.fetchMethod} or {@link OptionsBase.memoMethod}, then
643
+ * it will not be stored in the cache.
644
+ *
645
+ * Attempting to add an item whose calculated size is greater than
646
+ * this amount will not cache the item or evict any old items, but
647
+ * WILL delete an existing value if one is already present.
648
+ *
649
+ * Optional, must be a positive integer if provided. Defaults to
650
+ * the value of `maxSize` if provided.
437
651
  */
438
652
  maxEntrySize?: Size;
439
653
  /**
440
654
  * A function that returns a number indicating the item's size.
441
655
  *
656
+ * Requires {@link OptionsBase.maxSize} to be set.
657
+ *
442
658
  * If not provided, and {@link OptionsBase.maxSize} or
443
659
  * {@link OptionsBase.maxEntrySize} are set, then all
444
660
  * {@link LRUCache#set} calls **must** provide an explicit
@@ -447,8 +663,41 @@ export declare namespace LRUCache {
447
663
  sizeCalculation?: SizeCalculator<K, V>;
448
664
  /**
449
665
  * Method that provides the implementation for {@link LRUCache#fetch}
666
+ *
667
+ * ```ts
668
+ * fetchMethod(key, staleValue, { signal, options, context })
669
+ * ```
670
+ *
671
+ * If `fetchMethod` is not provided, then `cache.fetch(key)` is equivalent
672
+ * to `Promise.resolve(cache.get(key))`.
673
+ *
674
+ * If at any time, `signal.aborted` is set to `true`, or if the
675
+ * `signal.onabort` method is called, or if it emits an `'abort'` event
676
+ * which you can listen to with `addEventListener`, then that means that
677
+ * the fetch should be abandoned. This may be passed along to async
678
+ * functions aware of AbortController/AbortSignal behavior.
679
+ *
680
+ * The `fetchMethod` should **only** return `undefined` or a Promise
681
+ * resolving to `undefined` if the AbortController signaled an `abort`
682
+ * event. In all other cases, it should return or resolve to a value
683
+ * suitable for adding to the cache.
684
+ *
685
+ * The `options` object is a union of the options that may be provided to
686
+ * `set()` and `get()`. If they are modified, then that will result in
687
+ * modifying the settings to `cache.set()` when the value is resolved, and
688
+ * in the case of
689
+ * {@link OptionsBase.noDeleteOnFetchRejection} and
690
+ * {@link OptionsBase.allowStaleOnFetchRejection}, the handling of
691
+ * `fetchMethod` failures.
692
+ *
693
+ * For example, a DNS cache may update the TTL based on the value returned
694
+ * from a remote DNS server by changing `options.ttl` in the `fetchMethod`.
450
695
  */
451
696
  fetchMethod?: Fetcher<K, V, FC>;
697
+ /**
698
+ * Method that provides the implementation for {@link LRUCache#memo}
699
+ */
700
+ memoMethod?: Memoizer<K, V, FC>;
452
701
  /**
453
702
  * Set to true to suppress the deletion of stale data when a
454
703
  * {@link OptionsBase.fetchMethod} returns a rejected promise.
@@ -460,6 +709,18 @@ export declare namespace LRUCache {
460
709
  *
461
710
  * Note that the `get` return value will still be `undefined`
462
711
  * unless {@link OptionsBase.allowStale} is true.
712
+ *
713
+ * When using time-expiring entries with `ttl`, by default stale
714
+ * items will be removed from the cache when the key is accessed
715
+ * with `cache.get()`.
716
+ *
717
+ * Setting this option will cause stale items to remain in the cache, until
718
+ * they are explicitly deleted with `cache.delete(key)`, or retrieved with
719
+ * `noDeleteOnStaleGet` set to `false`.
720
+ *
721
+ * This may be overridden by passing an options object to `cache.get()`.
722
+ *
723
+ * Only relevant if a ttl is used.
463
724
  */
464
725
  noDeleteOnStaleGet?: boolean;
465
726
  /**
@@ -468,18 +729,52 @@ export declare namespace LRUCache {
468
729
  * promise.
469
730
  *
470
731
  * This differs from using {@link OptionsBase.allowStale} in that stale
471
- * data will ONLY be returned in the case that the
472
- * {@link LRUCache#fetch} fails, not any other times.
732
+ * data will ONLY be returned in the case that the {@link LRUCache#fetch}
733
+ * fails, not any other times.
734
+ *
735
+ * If a `fetchMethod` fails, and there is no stale value available, the
736
+ * `fetch()` will resolve to `undefined`. Ie, all `fetchMethod` errors are
737
+ * suppressed.
738
+ *
739
+ * Implies `noDeleteOnFetchRejection`.
740
+ *
741
+ * This may be set in calls to `fetch()`, or defaulted on the constructor,
742
+ * or overridden by modifying the options object in the `fetchMethod`.
473
743
  */
474
744
  allowStaleOnFetchRejection?: boolean;
475
745
  /**
476
746
  * Set to true to return a stale value from the cache when the
477
- * `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches an `'abort'`
478
- * event, whether user-triggered, or due to internal cache behavior.
747
+ * `AbortSignal` passed to the {@link OptionsBase.fetchMethod} dispatches
748
+ * an `'abort'` event, whether user-triggered, or due to internal cache
749
+ * behavior.
479
750
  *
480
751
  * Unless {@link OptionsBase.ignoreFetchAbort} is also set, the underlying
481
- * {@link OptionsBase.fetchMethod} will still be considered canceled, and its return
482
- * value will be ignored and not cached.
752
+ * {@link OptionsBase.fetchMethod} will still be considered canceled, and
753
+ * any value it returns will be ignored and not cached.
754
+ *
755
+ * Caveat: since fetches are aborted when a new value is explicitly
756
+ * set in the cache, this can lead to fetch returning a stale value,
757
+ * since that was the fallback value _at the moment the `fetch()` was
758
+ * initiated_, even though the new updated value is now present in
759
+ * the cache.
760
+ *
761
+ * For example:
762
+ *
763
+ * ```ts
764
+ * const cache = new LRUCache<string, any>({
765
+ * ttl: 100,
766
+ * fetchMethod: async (url, oldValue, { signal }) => {
767
+ * const res = await fetch(url, { signal })
768
+ * return await res.json()
769
+ * }
770
+ * })
771
+ * cache.set('https://example.com/', { some: 'data' })
772
+ * // 100ms go by...
773
+ * const result = cache.fetch('https://example.com/')
774
+ * cache.set('https://example.com/', { other: 'thing' })
775
+ * console.log(await result) // { some: 'data' }
776
+ * console.log(cache.get('https://example.com/')) // { other: 'thing' }
777
+ * ```
483
778
  */
484
779
  allowStaleOnFetchAbort?: boolean;
485
780
  /**
@@ -487,9 +782,9 @@ export declare namespace LRUCache {
487
782
  * object passed to {@link OptionsBase.fetchMethod}, and still cache the
488
783
  * resulting resolution value, as long as it is not `undefined`.
489
784
  *
490
- * When used on its own, this means aborted {@link LRUCache#fetch} calls are not
491
- * immediately resolved or rejected when they are aborted, and instead
492
- * take the full time to await.
785
+ * When used on its own, this means aborted {@link LRUCache#fetch} calls
786
+ * are not immediately resolved or rejected when they are aborted, and
787
+ * instead take the full time to await.
493
788
  *
494
789
  * When used with {@link OptionsBase.allowStaleOnFetchAbort}, aborted
495
790
  * {@link LRUCache#fetch} calls will resolve immediately to their stale
@@ -498,6 +793,26 @@ export declare namespace LRUCache {
498
793
  * not `undefined`, thus supporting a "return stale on timeout while
499
794
  * refreshing" mechanism by passing `AbortSignal.timeout(n)` as the signal.
500
795
  *
796
+ * For example:
797
+ *
798
+ * ```ts
799
+ * const c = new LRUCache({
800
+ * ttl: 100,
801
+ * ignoreFetchAbort: true,
802
+ * allowStaleOnFetchAbort: true,
803
+ * fetchMethod: async (key, oldValue, { signal }) => {
804
+ * // note: do NOT pass the signal to fetch()!
805
+ * // let's say this fetch can take a long time.
806
+ * const res = await fetch(`https://slow-backend-server/${key}`)
807
+ * return await res.json()
808
+ * },
809
+ * })
810
+ *
811
+ * // this will return the stale value after 100ms, while still
812
+ * // updating in the background for next time.
813
+ * const val = await c.fetch('key', { signal: AbortSignal.timeout(100) })
814
+ * ```
815
+ *
501
816
  * **Note**: regardless of this setting, an `abort` event _is still
502
817
  * emitted on the `AbortSignal` object_, so may result in invalid results
503
818
  * when passed to other underlying APIs that use AbortSignals.
@@ -522,7 +837,8 @@ export declare namespace LRUCache {
522
837
  */
523
838
  type Options<K, V, FC> = OptionsMaxLimit<K, V, FC> | OptionsSizeLimit<K, V, FC> | OptionsTTLLimit<K, V, FC>;
524
839
  /**
525
- * Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump}
840
+ * Entry objects used by {@link LRUCache#load} and {@link LRUCache#dump},
841
+ * and returned by {@link LRUCache#info}.
526
842
  */
527
843
  interface Entry<V> {
528
844
  value: V;
@@ -534,11 +850,17 @@ export declare namespace LRUCache {
534
850
  /**
535
851
  * Default export, the thing you're using this module to get.
536
852
  *
537
- * All properties from the options object (with the exception of
538
- * {@link OptionsBase.max} and {@link OptionsBase.maxSize}) are added as
539
- * normal public members. (`max` and `maxBase` are read-only getters.)
540
- * Changing any of these will alter the defaults for subsequent method calls,
541
- * but is otherwise safe.
853
+ * The `K` and `V` types define the key and value types, respectively. The
854
+ * optional `FC` type defines the type of the `context` object passed to
855
+ * `cache.fetch()` and `cache.memo()`.
856
+ *
857
+ * Keys and values **must not** be `null` or `undefined`.
858
+ *
859
+ * All properties from the options object (with the exception of `max`,
860
+ * `maxSize`, `fetchMethod`, `memoMethod`, `dispose` and `disposeAfter`) are
861
+ * added as normal public members. (The listed options are read-only getters.)
862
+ *
863
+ * Changing any of these will alter the defaults for subsequent method calls.
542
864
  */
543
865
  export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
544
866
  #private;
@@ -623,7 +945,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
623
945
  readonly head: Index;
624
946
  readonly tail: Index;
625
947
  free: StackLike;
626
- isBackgroundFetch: (p: any) => boolean;
948
+ isBackgroundFetch: (p: any) => p is BackgroundFetch<V>;
627
949
  backgroundFetch: (k: K, index: number | undefined, options: LRUCache.FetchOptions<K, V, FC>, context: any) => BackgroundFetch<V>;
628
950
  moveToTail: (index: number) => void;
629
951
  indexes: (options?: {
@@ -654,31 +976,37 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
654
976
  * {@link LRUCache.OptionsBase.fetchMethod} (read-only)
655
977
  */
656
978
  get fetchMethod(): LRUCache.Fetcher<K, V, FC> | undefined;
979
+ get memoMethod(): LRUCache.Memoizer<K, V, FC> | undefined;
657
980
  /**
658
981
  * {@link LRUCache.OptionsBase.dispose} (read-only)
659
982
  */
660
983
  get dispose(): LRUCache.Disposer<K, V> | undefined;
984
+ /**
985
+ * {@link LRUCache.OptionsBase.onInsert} (read-only)
986
+ */
987
+ get onInsert(): LRUCache.Inserter<K, V> | undefined;
661
988
  /**
662
989
  * {@link LRUCache.OptionsBase.disposeAfter} (read-only)
663
990
  */
664
991
  get disposeAfter(): LRUCache.Disposer<K, V> | undefined;
665
992
  constructor(options: LRUCache.Options<K, V, FC> | LRUCache<K, V, FC>);
666
993
  /**
667
- * Return the remaining TTL time for a given entry key
994
+ * Return the number of ms left in the item's TTL. If item is not in cache,
995
+ * returns `0`. Returns `Infinity` if item is in cache without a defined TTL.
668
996
  */
669
997
  getRemainingTTL(key: K): number;
670
998
  /**
671
999
  * Return a generator yielding `[key, value]` pairs,
672
1000
  * in order from most recently used to least recently used.
673
1001
  */
674
- entries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
1002
+ entries(): Generator<[K, V], void, unknown>;
675
1003
  /**
676
1004
  * Inverse order version of {@link LRUCache.entries}
677
1005
  *
678
1006
  * Return a generator yielding `[key, value]` pairs,
679
1007
  * in order from least recently used to most recently used.
680
1008
  */
681
- rentries(): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
1009
+ rentries(): Generator<(K | V)[], void, unknown>;
682
1010
  /**
683
1011
  * Return a generator yielding the keys in the cache,
684
1012
  * in order from most recently used to least recently used.
@@ -695,29 +1023,40 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
695
1023
  * Return a generator yielding the values in the cache,
696
1024
  * in order from most recently used to least recently used.
697
1025
  */
698
- values(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
1026
+ values(): Generator<V, void, unknown>;
699
1027
  /**
700
1028
  * Inverse order version of {@link LRUCache.values}
701
1029
  *
702
1030
  * Return a generator yielding the values in the cache,
703
1031
  * in order from least recently used to most recently used.
704
1032
  */
705
- rvalues(): Generator<V | BackgroundFetch<V> | undefined, void, unknown>;
1033
+ rvalues(): Generator<V | undefined, void, unknown>;
706
1034
  /**
707
1035
  * Iterating over the cache itself yields the same results as
708
1036
  * {@link LRUCache.entries}
709
1037
  */
710
- [Symbol.iterator](): Generator<(K | V | BackgroundFetch<V> | undefined)[], void, unknown>;
1038
+ [Symbol.iterator](): Generator<[K, V], void, unknown>;
1039
+ /**
1040
+ * A String value that is used in the creation of the default string
1041
+ * description of an object. Called by the built-in method
1042
+ * `Object.prototype.toString`.
1043
+ */
1044
+ [Symbol.toStringTag]: string;
711
1045
  /**
712
1046
  * Find a value for which the supplied fn method returns a truthy value,
713
- * similar to Array.find(). fn is called as fn(value, key, cache).
1047
+ * similar to `Array.find()`. fn is called as `fn(value, key, cache)`.
714
1048
  */
715
1049
  find(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => boolean, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
716
1050
  /**
717
- * Call the supplied function on each item in the cache, in order from
718
- * most recently used to least recently used. fn is called as
719
- * fn(value, key, cache). Does not update age or recenty of use.
720
- * Does not iterate over stale values.
1051
+ * Call the supplied function on each item in the cache, in order from most
1052
+ * recently used to least recently used.
1053
+ *
1054
+ * `fn` is called as `fn(value, key, cache)`.
1055
+ *
1056
+ * If `thisp` is provided, function will be called in the `this`-context of
1057
+ * the provided object, or the cache if no `thisp` object is provided.
1058
+ *
1059
+ * Does not update age or recenty of use, or iterate over stale values.
721
1060
  */
722
1061
  forEach(fn: (v: V, k: K, self: LRUCache<K, V, FC>) => any, thisp?: any): void;
723
1062
  /**
@@ -730,21 +1069,74 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
730
1069
  * false otherwise.
731
1070
  */
732
1071
  purgeStale(): boolean;
1072
+ /**
1073
+ * Get the extended info about a given entry, to get its value, size, and
1074
+ * TTL info simultaneously. Returns `undefined` if the key is not present.
1075
+ *
1076
+ * Unlike {@link LRUCache#dump}, which is designed to be portable and survive
1077
+ * serialization, the `start` value is always the current timestamp, and the
1078
+ * `ttl` is a calculated remaining time to live (negative if expired).
1079
+ *
1080
+ * Always returns stale values, if their info is found in the cache, so be
1081
+ * sure to check for expirations (ie, a negative {@link LRUCache.Entry#ttl})
1082
+ * if relevant.
1083
+ */
1084
+ info(key: K): LRUCache.Entry<V> | undefined;
733
1085
  /**
734
1086
  * Return an array of [key, {@link LRUCache.Entry}] tuples which can be
735
- * passed to cache.load()
1087
+ * passed to {@link LRUCache#load}.
1088
+ *
1089
+ * The `start` fields are calculated relative to a portable `Date.now()`
1090
+ * timestamp, even if `performance.now()` is available.
1091
+ *
1092
+ * Stale entries are always included in the `dump`, even if
1093
+ * {@link LRUCache.OptionsBase.allowStale} is false.
1094
+ *
1095
+ * Note: this returns an actual array, not a generator, so it can be more
1096
+ * easily passed around.
736
1097
  */
737
1098
  dump(): [K, LRUCache.Entry<V>][];
738
1099
  /**
739
1100
  * Reset the cache and load in the items in entries in the order listed.
740
- * Note that the shape of the resulting cache may be different if the
741
- * same options are not used in both caches.
1101
+ *
1102
+ * The shape of the resulting cache may be different if the same options are
1103
+ * not used in both caches.
1104
+ *
1105
+ * The `start` fields are assumed to be calculated relative to a portable
1106
+ * `Date.now()` timestamp, even if `performance.now()` is available.
742
1107
  */
743
1108
  load(arr: [K, LRUCache.Entry<V>][]): void;
744
1109
  /**
745
1110
  * Add a value to the cache.
1111
+ *
1112
+ * Note: if `undefined` is specified as a value, this is an alias for
1113
+ * {@link LRUCache#delete}
1114
+ *
1115
+ * Fields on the {@link LRUCache.SetOptions} options param will override
1116
+ * their corresponding values in the constructor options for the scope
1117
+ * of this single `set()` operation.
1118
+ *
1119
+ * If `start` is provided, then that will set the effective start
1120
+ * time for the TTL calculation. Note that this must be a previous
1121
+ * value of `performance.now()` if supported, or a previous value of
1122
+ * `Date.now()` if not.
1123
+ *
1124
+ * Options object may also include `size`, which will prevent
1125
+ * calling the `sizeCalculation` function and just use the specified
1126
+ * number if it is a positive integer, and `noDisposeOnSet` which
1127
+ * will prevent calling a `dispose` function in the case of
1128
+ * overwrites.
1129
+ *
1130
+ * If the `size` (or return value of `sizeCalculation`) for a given
1131
+ * entry is greater than `maxEntrySize`, then the item will not be
1132
+ * added to the cache.
1133
+ *
1134
+ * Will update the recency of the entry.
1135
+ *
1136
+ * If the value is `undefined`, then this is an alias for
1137
+ * `cache.delete(key)`. `undefined` is never stored in the cache.
746
1138
  */
747
- set(k: K, v: V | BackgroundFetch<V>, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
1139
+ set(k: K, v: V | BackgroundFetch<V> | undefined, setOptions?: LRUCache.SetOptions<K, V, FC>): this;
748
1140
  /**
749
1141
  * Evict the least recently used item, returning its value or
750
1142
  * `undefined` if cache is empty.
@@ -755,6 +1147,14 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
755
1147
  * Will return false if the item is stale, even though it is technically
756
1148
  * in the cache.
757
1149
  *
1150
+ * Check if a key is in the cache, without updating the recency of
1151
+ * use. Age is updated if {@link LRUCache.OptionsBase.updateAgeOnHas} is set
1152
+ * to `true` in either the options or the constructor.
1153
+ *
1154
+ * Will return `false` if the item is stale, even though it is technically in
1155
+ * the cache. The difference can be determined (if it matters) by using a
1156
+ * `status` argument, and inspecting the `has` field.
1157
+ *
758
1158
  * Will not update item age unless
759
1159
  * {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
760
1160
  */
@@ -771,6 +1171,25 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
771
1171
  * Make an asynchronous cached fetch using the
772
1172
  * {@link LRUCache.OptionsBase.fetchMethod} function.
773
1173
  *
1174
+ * If the value is in the cache and not stale, then the returned
1175
+ * Promise resolves to the value.
1176
+ *
1177
+ * If not in the cache, or beyond its TTL staleness, then
1178
+ * `fetchMethod(key, staleValue, { options, signal, context })` is
1179
+ * called, and the value returned will be added to the cache once
1180
+ * resolved.
1181
+ *
1182
+ * If called with `allowStale`, and an asynchronous fetch is
1183
+ * currently in progress to reload a stale value, then the former
1184
+ * stale value will be returned.
1185
+ *
1186
+ * If called with `forceRefresh`, then the cached item will be
1187
+ * re-fetched, even if it is not stale. However, if `allowStale` is also
1188
+ * set, then the old value will still be returned. This is useful
1189
+ * in cases where you want to force a reload of a cached value. If
1190
+ * a background fetch is already in progress, then `forceRefresh`
1191
+ * has no effect.
1192
+ *
774
1193
  * If multiple fetches for the same key are issued, then they will all be
775
1194
  * coalesced into a single call to fetchMethod.
776
1195
  *
@@ -783,9 +1202,89 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
783
1202
  * This is a known (fixable) shortcoming which will be addresed on when
784
1203
  * someone complains about it, as the fix would involve added complexity and
785
1204
  * may not be worth the costs for this edge case.
1205
+ *
1206
+ * If {@link LRUCache.OptionsBase.fetchMethod} is not specified, then this is
1207
+ * effectively an alias for `Promise.resolve(cache.get(key))`.
1208
+ *
1209
+ * When the fetch method resolves to a value, if the fetch has not
1210
+ * been aborted due to deletion, eviction, or being overwritten,
1211
+ * then it is added to the cache using the options provided.
1212
+ *
1213
+ * If the key is evicted or deleted before the `fetchMethod`
1214
+ * resolves, then the AbortSignal passed to the `fetchMethod` will
1215
+ * receive an `abort` event, and the promise returned by `fetch()`
1216
+ * will reject with the reason for the abort.
1217
+ *
1218
+ * If a `signal` is passed to the `fetch()` call, then aborting the
1219
+ * signal will abort the fetch and cause the `fetch()` promise to
1220
+ * reject with the reason provided.
1221
+ *
1222
+ * **Setting `context`**
1223
+ *
1224
+ * If an `FC` type is set to a type other than `unknown`, `void`, or
1225
+ * `undefined` in the {@link LRUCache} constructor, then all
1226
+ * calls to `cache.fetch()` _must_ provide a `context` option. If
1227
+ * set to `undefined` or `void`, then calls to fetch _must not_
1228
+ * provide a `context` option.
1229
+ *
1230
+ * The `context` param allows you to provide arbitrary data that
1231
+ * might be relevant in the course of fetching the data. It is only
1232
+ * relevant for the course of a single `fetch()` operation, and
1233
+ * discarded afterwards.
1234
+ *
1235
+ * **Note: `fetch()` calls are inflight-unique**
1236
+ *
1237
+ * If you call `fetch()` multiple times with the same key value,
1238
+ * then every call after the first will resolve on the same
1239
+ * promise<sup>1</sup>,
1240
+ * _even if they have different settings that would otherwise change
1241
+ * the behavior of the fetch_, such as `noDeleteOnFetchRejection`
1242
+ * or `ignoreFetchAbort`.
1243
+ *
1244
+ * In most cases, this is not a problem (in fact, only fetching
1245
+ * something once is what you probably want, if you're caching in
1246
+ * the first place). If you are changing the fetch() options
1247
+ * dramatically between runs, there's a good chance that you might
1248
+ * be trying to fit divergent semantics into a single object, and
1249
+ * would be better off with multiple cache instances.
1250
+ *
1251
+ * **1**: Ie, they're not the "same Promise", but they resolve at
1252
+ * the same time, because they're both waiting on the same
1253
+ * underlying fetchMethod response.
1254
+ */
1255
+ fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<undefined | V>;
1256
+ fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<undefined | V>;
1257
+ /**
1258
+ * In some cases, `cache.fetch()` may resolve to `undefined`, either because
1259
+ * a {@link LRUCache.OptionsBase#fetchMethod} was not provided (turning
1260
+ * `cache.fetch(k)` into just an async wrapper around `cache.get(k)`) or
1261
+ * because `ignoreFetchAbort` was specified (either to the constructor or
1262
+ * in the {@link LRUCache.FetchOptions}). Also, the
1263
+ * {@link LRUCache.OptionsBase.fetchMethod} may return `undefined` or `void`, making
1264
+ * the test even more complicated.
1265
+ *
1266
+ * Because inferring the cases where `undefined` might be returned are so
1267
+ * cumbersome, but testing for `undefined` can also be annoying, this method
1268
+ * can be used, which will reject if `this.fetch()` resolves to undefined.
786
1269
  */
787
- fetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<void | V>;
788
- fetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V, FC> : never): Promise<void | V>;
1270
+ forceFetch(k: K, fetchOptions: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : LRUCache.FetchOptionsWithContext<K, V, FC>): Promise<V>;
1271
+ forceFetch(k: unknown extends FC ? K : FC extends undefined | void ? K : never, fetchOptions?: unknown extends FC ? LRUCache.FetchOptions<K, V, FC> : FC extends undefined | void ? LRUCache.FetchOptionsNoContext<K, V> : never): Promise<V>;
1272
+ /**
1273
+ * If the key is found in the cache, then this is equivalent to
1274
+ * {@link LRUCache#get}. If not, in the cache, then calculate the value using
1275
+ * the {@link LRUCache.OptionsBase.memoMethod}, and add it to the cache.
1276
+ *
1277
+ * If an `FC` type is set to a type other than `unknown`, `void`, or
1278
+ * `undefined` in the LRUCache constructor, then all calls to `cache.memo()`
1279
+ * _must_ provide a `context` option. If set to `undefined` or `void`, then
1280
+ * calls to memo _must not_ provide a `context` option.
1281
+ *
1282
+ * The `context` param allows you to provide arbitrary data that might be
1283
+ * relevant in the course of fetching the data. It is only relevant for the
1284
+ * course of a single `memo()` operation, and discarded afterwards.
1285
+ */
1286
+ memo(k: K, memoOptions: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : LRUCache.MemoOptionsWithContext<K, V, FC>): V;
1287
+ memo(k: unknown extends FC ? K : FC extends undefined | void ? K : never, memoOptions?: unknown extends FC ? LRUCache.MemoOptions<K, V, FC> : FC extends undefined | void ? LRUCache.MemoOptionsNoContext<K, V> : never): V;
789
1288
  /**
790
1289
  * Return a value from the cache. Will update the recency of the cache
791
1290
  * entry found.
@@ -795,6 +1294,7 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
795
1294
  get(k: K, getOptions?: LRUCache.GetOptions<K, V, FC>): V | undefined;
796
1295
  /**
797
1296
  * Deletes a key out of the cache.
1297
+ *
798
1298
  * Returns true if the key was deleted, false otherwise.
799
1299
  */
800
1300
  delete(k: K): boolean;
@@ -803,5 +1303,4 @@ export declare class LRUCache<K extends {}, V extends {}, FC = unknown> {
803
1303
  */
804
1304
  clear(): void;
805
1305
  }
806
- export default LRUCache;
807
1306
  //# sourceMappingURL=index.d.ts.map