Interface CachingRequestCacheFirstConfig<T>

Configuration for requests with caching enabled

interface CachingRequestCacheFirstConfig<T> {
    activeCache?: string | string[];
    cacheTimeout?: number;
    defaultCacheControl?: CacheControl;
    equal?: ((t1: T, t2: T) => boolean);
    forcedCacheControl?: CacheControl;
    key: string;
    mode?: "cacheControl" | "race";
    table?: string;
    update?: boolean;
}

Type Parameters

  • T

Hierarchy (view full)

Properties

activeCache?: string | string[]

Specify specific cache(s) to use

cacheTimeout?: number
defaultCacheControl?: CacheControl

These settings are applied if the respective headers are not set on the cached response.

equal?: ((t1: T, t2: T) => boolean)

Default is a structureClone comparison method

Type declaration

    • (t1, t2): boolean
    • Parameters

      • t1: T
      • t2: T

      Returns boolean

forcedCacheControl?: CacheControl

These settings overwrite the respective response headers.

key: string

Specify the cache key for this particular request

mode?: "cacheControl" | "race"

Default: "cacheControl", i.e. evaluate response headers to determine max cache time etc., and try to read from cache first before sending any request to the server.

table?: string

Specify a table name for the request; if none specified, a default is used. This can be used to separate requests of different kinds.

update?: boolean

Provide an updated fetched value later if a cached result is returned. Note that if the cache is fresh this will not trigger and return a failed promise. In order to force trigger it, provide a forcedCachControl: {maxAge: 0} argument as well (or no-cache directive?). If the no-cache directive is set (always revalidate before re-use cached values) the returned promise will always fail as well.