Interface IEntityCacheAdapter<TFields>

A cache adapter is an interface by which objects can be cached, fetched from cache, and removed from cache (invalidated).

interface IEntityCacheAdapter<TFields> {
    cacheDBMissesAsync<N>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<void>;
    cacheManyAsync<N>(fieldName: N, objectMap: ReadonlyMap<NonNullable<TFields[N]>, Readonly<TFields>>): Promise<void>;
    invalidateManyAsync<N>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<void>;
    loadManyAsync<N>(fieldName: N, fieldValues: readonly NonNullable<TFields[N]>[]): Promise<ReadonlyMap<NonNullable<TFields[N]>, CacheLoadResult<TFields>>>;
}

Type Parameters

  • TFields

Implemented by

Methods

  • Negatively cache objects that could not be found in the cache or DB.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N

      object field being queried

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

      fieldValues for objects reported as CacheStatus.NEGATIVE in the cache and not found in the DB.

    Returns Promise<void>

  • Cache many objects fetched from the DB.

    Type Parameters

    • N extends string | number | symbol

    Parameters

    • fieldName: N

      object field being queried

    • objectMap: ReadonlyMap<NonNullable<TFields[N]>, Readonly<TFields>>

      map from field value to object to cache

    Returns Promise<void>

  • 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>