Wrap a function with time-to-live (TTL) caching.

  • Type Parameters

    • T extends ((...args: A) => any)

      The function type.

    • A extends any[]

      The argument types of the function.

    • K = string

      The key type for caching.

    Parameters

    • run: T

      The function to wrap.

    • options: {
          key?: ((args: A) => K);
          timeout?: number;
      } = {}

      The configuration options.

      • Optionalkey?: ((args: A) => K)

        The key generator function that generates a key based on function arguments.

          • (args): K
          • Parameters

            • args: A

            Returns K

      • Optionaltimeout?: number

        The TTL duration in milliseconds.

    Returns T & IClearable<K> & IControl<K, ReturnType<T>>

    • The wrapped function with caching capability.