Class ReadThroughEntityCache<TFields>

A read-through entity cache is responsible for coordinating EntityDatabaseAdapter and EntityCacheAdapter within the EntityDataManager.

Type Parameters

  • TFields extends Record<string, any>

Constructors

Methods

  • Invalidate the cache for objects cached by (fieldName, fieldValue).

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N

      object field being queried

    • fieldValues: readonly NonNullable<TFields[N]>[]

      fieldName field values to be invalidated

    Returns Promise<void>

  • Read-through cache function. Steps:

    1. Check for cached (fieldName, fieldValue) objects
    2. Query the fetcher for fieldValues not in the cache
    3. Cache the results from the fetcher
    4. Negatively cache anything missing from the fetcher
    5. Return the full set of data for the query.

    If cache is not applicable for fieldName, return results from fetcher.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N

      object field being queried

    • fieldValues: readonly NonNullable<TFields[N]>[]

      fieldName field values being queried

    • fetcher: ((fetcherFieldValues: readonly NonNullable<TFields[N]>[]) => Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Readonly<TFields>[]>>)

      closure used to provide underlying data source objects for fieldName and fetcherFieldValues

        • (fetcherFieldValues): Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Readonly<TFields>[]>>
        • Parameters

          • fetcherFieldValues: readonly NonNullable<TFields[N]>[]

          Returns Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Readonly<TFields>[]>>

    Returns Promise<ReadonlyMap<NonNullable<TFields[N]>, readonly Readonly<TFields>[]>>

    map from fieldValue to objects that match the query for that fieldValue