Class LoadNCache<T>

The main class of this project. Check README.md for documentation.

Type Parameters

  • T

Hierarchy

  • EventEmitter
    • LoadNCache

Constructors

  • The LoadNCache constructor accept an options object. If default options are ok for you then you can pass in a function. Passing a function is equivalent to passing only the loader option in the options parameter.

    Type Parameters

    • T

    Parameters

    • cfg: Configuration<T> | (() => Promise<T>)

      Instance settings or a load function.

    Returns LoadNCache<T>

Properties

autoflushManager?: AutoflushManager<T>

AutoflushManager casted to right type.

config: Configuration<T>

The actual configuration including defaults.

firstLoad: boolean = true

Is this the first time we load a value?

metadata?: PromiseWithMetadata<T>

Metadata associated to the promise below.

persistenceManager: PersistenceManager<T>

Persistence manager casted to right type.

promise?: Promise<T>

The promise holding the value.

Methods

  • Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional context: any

    Returns LoadNCache<T>

  • Invoke the loadFunction ensuring that its returned value is a promise. The check is ensured implicitly by using the async qualifier.

    Returns Promise<T>

  • Calls each of the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Rest ...args: any[]

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

  • Invalidate the currently cached value if any. If no value is cached then this method does nothing. Each subsequent call to .get() will get a different promise object then before.

    Returns Promise<void>

  • Retrieve the value. Always returns a promise. This call will result in the invocation of loadFunction if no cached value is available at the time.

    Returns

    A promise that will be resolved with the value or reject if fetching fails.

    Returns Promise<T>

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T

    Returns ((...args: any[]) => void)[]

  • This method load a new value from storage or by calling a loadFunction. As soon as the value is available (which can be also a rejected promise) its stored as a promise along with the timestamp.

    Returns Promise<PromiseWithMetadata<T>>

  • Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Optional fn: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns LoadNCache<T>

  • Add a listener for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional context: any

    Returns LoadNCache<T>

  • Add a one-time listener for a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • fn: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional context: any

    Returns LoadNCache<T>

  • Shortcut for calling .flush() and .get(). Returns the promise from .get().

    Returns

    the same promise that .get() would return.

    Returns Promise<T>

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol

    Returns LoadNCache<T>

  • Remove the listeners of a given event.

    Type Parameters

    • T extends string | symbol

    Parameters

    • event: T
    • Optional fn: ((...args: any[]) => void)
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional context: any
    • Optional once: boolean

    Returns LoadNCache<T>

  • Calls the persistenceManager clear method handling exceptions.

    Returns Promise<void>

  • Calls the persistenceManager saveValue method handling exceptions.

    Parameters

    • promise: PromiseWithMetadata<T>

      The PromiseWithMetadata object that stores the data to persist.

    Returns Promise<void>

Generated using TypeDoc