Skip to main content

SharedResponseCache

Keeps responses by key (normally the URL) for their max-age, and shares a request already in flight, so several layers over one feed (alerts split by type) cost one request.

This is a class exported by @mapcairn/core, checked against version 0.2.0.

Signature​

import { SharedResponseCache } from "@mapcairn/core";

class SharedResponseCache<T>

Type parameters​

  • T

Constructors​

(constructor)​

constructor(options: SharedResponseCacheOptions);

Constructs a new instance of the SharedResponseCache class

  • options (SharedResponseCacheOptions)

Methods​

load​

load(key: string, start: (signal: AbortSignal) => Promise<CachedResponse<T>>, signal?: AbortSignal): Promise<T>;

Returns the fresh value for key, joins a request in flight, or calls start with a signal the cache controls.

  • key (string)
  • start ((signal: AbortSignal) => Promise<CachedResponse<T>>)
  • signal? (AbortSignal)

Remarks​

Each caller may pass its own signal. A caller that gives up is rejected with LayerError aborted at once, but the request carries on for the others; only when every caller has given up is it cancelled. Failures are passed to every waiting caller and never kept.

See also​

Source: packages/core/src/layers/responseCache.ts:62