[]previous and next page

DataCacheOptions

Options of createDataCache.

Options of createDataCache.

Import#

ts
import type { DataCacheOptions } from "@shadow-js/dusk/server";

Signature#

ts
interface DataCacheOptions {
  /** Where the values are kept (any {@link KVStore}). */
  readonly kv: KVStore;
  /** Named lifetimes that add to or replace the presets (see `cache-life.ts`). */
  readonly profiles?: Readonly<
    Record<
      string,
      Partial<CacheLifeProfile> & Pick<CacheLifeProfile, "stale" | "revalidate" | "expire">
    >
  >;
  /** Keys with a run in flight at once; past it a call runs on its own, uncoalesced. Default 10 000. */
  readonly maxInFlight?: number;
  /** Callers that share one run; the caller past it runs on its own (nothing is refused). Default 1 000. */
  readonly maxWaiters?: number;
  /** Milliseconds after which a run is abandoned: its callers fail with a `TimeoutError`. `0`: never. Default 30 000. */
  readonly timeoutMs?: number;
  /** Wait after the first failed background refresh of a key, in milliseconds; each failure doubles it. Default 1 000. */
  readonly backoffBaseMs?: number;
  /** Longest wait between two refreshes of a key that keeps failing, in milliseconds. Default 60 000. */
  readonly backoffMaxMs?: number;
  /** Largest stored value in bytes of JSON. Default 1 MiB. */
  readonly maxValueBytes?: number;
  /** Keys a tag indexes; the oldest leaves the index past it. Default 10 000. */
  readonly maxKeysPerTag?: number;
  /** Key prefix. Default `"dusk:data:"`. */
  readonly prefix?: string;
  /** Clock in epoch milliseconds. Default `Date.now`. */
  readonly now?: () => number;
  /** Receives a background refresh that failed. Default: `console.error`. */
  readonly report?: (error: unknown) => void;
}

Members#

Name Type Description
kv readonly kv: KVStore Where the values are kept (any KVStore).
profiles? readonly profiles?: Readonly< Record< string, Partial<CacheLifeProfile> & Pick<CacheLifeProfile, "stale" | "revalidate" | "expire"> > > Named lifetimes that add to or replace the presets (see cache-life.ts).
maxInFlight? readonly maxInFlight?: number Keys with a run in flight at once; past it a call runs on its own, uncoalesced. Default 10 000.
maxWaiters? readonly maxWaiters?: number Callers that share one run; the caller past it runs on its own (nothing is refused). Default 1 000.
timeoutMs? readonly timeoutMs?: number Milliseconds after which a run is abandoned: its callers fail with a TimeoutError. 0: never. Default 30 000.
backoffBaseMs? readonly backoffBaseMs?: number Wait after the first failed background refresh of a key, in milliseconds; each failure doubles it. Default 1 000.
backoffMaxMs? readonly backoffMaxMs?: number Longest wait between two refreshes of a key that keeps failing, in milliseconds. Default 60 000.
maxValueBytes? readonly maxValueBytes?: number Largest stored value in bytes of JSON. Default 1 MiB.
maxKeysPerTag? readonly maxKeysPerTag?: number Keys a tag indexes; the oldest leaves the index past it. Default 10 000.
prefix? readonly prefix?: string Key prefix. Default "dusk:data:".
now? readonly now?: () => number Clock in epoch milliseconds. Default Date.now.
report? readonly report?: (error: unknown) => void Receives a background refresh that failed. Default: console.error.