toolish - v0.2.5
    Preparing search index...

    Class TtlCache<T, P>

    Basic key-value cache that stores the results of a given load function based on the parameters that are passed to it. Results remain valid for a limited time (Time To Live). Note that expired results are not proactively cleared, they're just reloaded once requested again.

    Type Parameters

    • T
    • P extends any[]

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    OPTIONS: TtlCacheOptions<any> = ...

    Default options. Change these to apply your preferred configuration. Changes apply only to future cache instances.

    entries: Map<string, TtlCacheEntry<T>> = ...
    options: TtlCacheOptions<P>

    Methods

    • Returns the value associated with the given parameters if available and not expired, or calls the load function to generate it.

      Parameters

      • ...params: P

        parameters for the load function.

      Returns Promise<T>

    • Returns any value currently associated with the given parameters, even if expired.

      Parameters

      • ...params: P

        parameters for the load function.

      Returns undefined | T

    • Discards all stored values.

      Returns void