EndpointCacheclass

new EndpointCache<P, R>(endpoint: Endpoint<P, R>, provider: APIProvider<P, R>)
ParamType
endpointEndpoint<P, R>
The endpoint that every cached store fetches from. required
providerAPIProvider<P, R>
The APIProvider used to render URLs and fetch results. required
Return
EndpointCache<P, R>
Cache of EndpointStore objects for a single endpoint, keyed by the rendered request URL of each payload.
PropertyType
.endpointEndpoint<P, R>
The endpoint that every store in this cache fetches from. required readonly
.providerAPIProvider<P, R>
The APIProvider used to render URLs and fetch results for this endpoint. required readonly

Cache of EndpointStore objects for a single endpoint, keyed by the rendered request URL of each payload.

  • Use get(payload) to retrieve or create the EndpointStore for a given payload.
  • Disposing the cache disposes every nested EndpointStore and clears the map.

Examples

const cache = new EndpointCache(getUser, provider);
const user = await cache.call({ id: "abc" });

Methods

Go

EndpointCache.get()method

Get (or create) the EndpointStore for the given payload.

get(payload: P, caller: AnyCaller = this.get): EndpointStore<P, R>
Go

EndpointCache.call()method

Fetch (or return a cached result) for the given payload.

call(payload: P, maxAge: number = AVOID_REFRESH, caller: AnyCaller = this.call): Promise<R>
Go

EndpointCache.invalidate()method

Invalidate a specific store so the next read refetches.

invalidate(payload: P, caller: AnyCaller = this.invalidate): void
Go

EndpointCache.invalidateAll()method

Invalidate all stores so the next read of any payload refetches.

invalidateAll(): void
Go

EndpointCache.refresh()method

Trigger a refetch on a specific store.

refresh(payload: P, maxAge?: number, caller: AnyCaller = this.invalidate): Promise<void>
Go

EndpointCache.refreshAll()method

Trigger a refetch on all stores.

refreshAll(maxAge?: number): Promise<void>