Options
All
  • Public
  • Public/Protected
  • All
Menu

The class Cache represents as store of values that can be retrieves from keys.

There are two kind of keys:

  • ValueKey: equality of keys are based on value
  • ReferenceKey: equality of keys are based on reference(s)

Usage of ReferenceKey should be preferred whenever possible (it does not involves serialization). In practice:

  • when the key is based on values contains in the data part of a message, ReferenceKey are used.
  • when the key is based on values contains in the configuration part of a message, ValueKey are used (due to the step of mergeConfiguration, modules always receive new instances of configuration).

Every [[ModuleFlux | module]] contains an instance of this class, it is provided as second argument of an input's onTriggered callback.

Hierarchy

  • Cache

Index

Constructors

constructor

Properties

Private cachedObjects

cachedObjects: [CacheKey, unknown][] = ...

Private maxCount

maxCount: number = 1

Methods

Private getCached

  • getCached(key: CacheKey): unknown

getOrCreate

  • getOrCreate<TValue>(key: CacheKey, creatorFct: (context?: Context) => TValue, context?: Context): TValue
  • Get a value from the cache or generate it if not available. Synchronous version.

    Type parameters

    • TValue

    Parameters

    • key: CacheKey
    • creatorFct: (context?: Context) => TValue

      value generator

        • Parameters

          Returns TValue

    • Optional context: Context

      execution context, if provided:

      • if the value is created: a child context is appended to it and passed to the generator function
      • if the value is retrieved: a [[LogInfo]] entry is appended to it

    Returns TValue

    the value, either retrieved or created

getOrCreate$

  • getOrCreate$<T>(key: CacheKey, creatorFct$: (context?: Context) => Observable<T>, context?: Context): Observable<T>
  • Get a value from the cache or generate it if not available. Asynchronous version.

    Type parameters

    • T

    Parameters

    • key: CacheKey
    • creatorFct$: (context?: Context) => Observable<T>
        • (context?: Context): Observable<T>
        • Parameters

          Returns Observable<T>

    • Optional context: Context

      execution context, if provided:

      • if the value is created: a child context is appended to it and passed to the generator function
      • if the value is retrieved: a [[LogInfo]] entry is appended to it

    Returns Observable<T>

    Observable on value, either retrieved or created

getOrCreateWithStatus

  • getOrCreateWithStatus<TKey, TValue>(key: CacheKey, creatorFct: (context?: Context) => TValue, context?: Context): [TValue, boolean]
  • Get a value from the cache or generate it if not available. Synchronous version.

    Type parameters

    • TKey

    • TValue

    Parameters

    • key: CacheKey
    • creatorFct: (context?: Context) => TValue

      value generator

        • Parameters

          Returns TValue

    • Optional context: Context

      execution context, if provided:

      • if the value is created: a child context is appended to it and passed to the generator function
      • if the value is retrieved: a [[LogInfo]] entry is appended to it

    Returns [TValue, boolean]

    , value: the value (either retrieved or created), fromCache: true if the value was in the cache

getOrCreateWithStatus$

  • getOrCreateWithStatus$<T>(key: CacheKey, creatorFct$: (context?: Context) => Observable<T>, context?: Context): Observable<[T, boolean]>
  • Get a value from the cache or generate it if not available. Asynchronous version.

    Type parameters

    • T

    Parameters

    • key: CacheKey
    • creatorFct$: (context?: Context) => Observable<T>
        • (context?: Context): Observable<T>
        • Parameters

          Returns Observable<T>

    • Optional context: Context

      execution context, if provided:

      • if the value is created: a child context is appended to it and passed to the generator function
      • if the value is retrieved: a [[LogInfo]] entry is appended to it

    Returns Observable<[T, boolean]>

    Observable on [value, fromCache], value: the value (either retrieved or created), fromCache: true if the value was in the cache

Private postProcess

  • postProcess<TObj>(key: CacheKey, obj: TObj): TObj

setCapacity

  • setCapacity(count: number): void
  • Set the maximum number of items of the store

    Parameters

    • count: number

      maximum number of items

    Returns void

Generated using TypeDoc