CachedAPIProvider.invalidate()method
Invalidate the cached result for a specific endpoint and payload.
invalidate(endpoint: Endpoint<PP, RR>, payload: PP): void
new CachedAPIProvider<P, R>(source: APIProvider<P, R>, maxAge: number = AVOID_REFRESH)
| Param | Type | |
|---|---|---|
source | APIProvider<P, R> | The source provider whose results are cached. required |
maxAge | number | Default maximum age in milliseconds for call() (defaults to AVOID_REFRESH). Defaults to AVOID_REFRESH |
| Return | |
|---|---|
CachedAPIProvider<P, R> | API provider wrapper that serves requests through an APICache so repeated calls reuse cached results. |
| Property | Type | |
|---|---|---|
.maxAge | number | The maximum age used when calling call(), defaulting to AVOID_REFRESH (only refresh if invalidated or still loading).- Not used for refresh() calls, which always refetch immediately. readonly |
API provider wrapper that serves requests through an APICache so repeated calls reuse cached results.
call(...), triggers cache.refresh(maxAge) for the endpoint+payload before awaiting cache.call(...).invalidate, invalidateAll, refresh, and refreshAll pass through to the underlying cache and use this.maxAge as the default refresh timing.A wrapping provider that serves calls through an APICache. Repeated calls for the same endpoint and payload skip the network and return the cached value, and it exposes invalidate / refresh helpers for cache control.
The constructor takes the source provider and an optional default maxAge (defaults to AVOID_REFRESH — only refetch when a value is missing or invalidated).
import { CachedAPIProvider, ValidationAPIProvider, ClientAPIProvider } from "shelving/api"
const provider = new CachedAPIProvider(
new ValidationAPIProvider(new ClientAPIProvider({ url: "https://api.example.com" }))
)
await provider.call(getUser, { id: "u_1" }) // fetches
await provider.call(getUser, { id: "u_1" }) // returns cached
provider.invalidate(getUser, { id: "u_1" }) // mark stale
provider.refresh(getUser, { id: "u_1" }) // re-fetch eagerlyinvalidateAll(endpoint) and refreshAll(endpoint) act on every cached payload for an endpoint at once.
const api = new CachedAPIProvider(source); const result = await api.call(endpoint, payload);
Invalidate the cached result for a specific endpoint and payload.
invalidate(endpoint: Endpoint<PP, RR>, payload: PP): void
Invalidate every cached result for an endpoint, across all payloads.
invalidateAll(endpoint: Endpoint<PP, RR>): void
Refresh the cached result for a specific endpoint and payload.
refresh(endpoint: Endpoint<PP, RR>, payload: PP): void
Refresh every cached result for an endpoint, across all payloads.
refreshAll(endpoint: Endpoint<PP, RR>): void