APICache.get()method
Get (or create) the EndpointCache for the given endpoint.
get(endpoint: Endpoint<PP, RR>): EndpointCache<PP, RR>
get(endpoint: Endpoint): EndpointCache
new APICache<P, R>(provider: APIProvider<P, R>)
| Param | Type | |
|---|---|---|
provider | APIProvider<P, R> | The APIProvider used to fetch results for every cached endpoint. required |
| Return | |
|---|---|
APICache<P, R> | Cache of EndpointCache objects keyed by Endpoint, providing memoised API results across many endpoints. |
| Property | Type | |
|---|---|---|
.provider | APIProvider<P, R> |
Cache of EndpointCache objects keyed by Endpoint, providing memoised API results across many endpoints.
get(endpoint) to retrieve or create the EndpointCache for a given endpoint, then get(payload) on that to get a specific EndpointStore.EndpointCache and clears the map.const cache = new APICache(provider);
const user = await cache.call(getUser, { id: "abc" });Get (or create) the EndpointCache for the given endpoint.
get(endpoint: Endpoint<PP, RR>): EndpointCache<PP, RR>
get(endpoint: Endpoint): EndpointCache
Fetch (or return a cached result) for the given endpoint and payload.
call(endpoint: Endpoint<PP, RR>, payload: PP, maxAge: number = AVOID_REFRESH, caller: AnyCaller = this.call): Promise<RR>
Invalidate a specific store for an endpoint so the next read refetches.
invalidate(endpoint: Endpoint<PP, RR>, payload: PP): void
Invalidate all stores for an endpoint so the next read of any payload refetches.
invalidateAll(endpoint: Endpoint<PP, RR>): void
Trigger a refetch on a specific store for an endpoint.
refresh(endpoint: Endpoint<PP, RR>, payload: PP, maxAge?: number): void
Trigger a refetch on all stores for an endpoint.
refreshAll(endpoint: Endpoint<PP, RR>, maxAge?: number): void