DataCache
The data cache of one handler.
The data cache of one handler.
Import#
ts
import type { DataCache } from "@shadow-js/dusk/server";
Signature#
ts
interface DataCache {
/**
* Returns the cached value for the key, or runs `fn` and stores its result. `fn` receives the signal of the shared
* run (see `CacheDataOptions.signal`); a function that ignores it is fine.
*/
cacheData<T>(fn: (signal: AbortSignal) => Promise<T>, options: CacheDataOptions): Promise<T>;
/** Fetches a GET URL through the cache; a JSON answer is parsed. Public data only (see the guide). */
cachedFetch<T = unknown>(
input: string | URL,
init: CachedFetchInit | undefined,
options: CachedFetchOptions,
): Promise<T>;
/** Removes every entry indexed under the tag. */
purgeTag(tag: string): Promise<void>;
/** Runs in flight (for tests and diagnostics). */
readonly inFlight: number;
}
Members#
| Name | Type | Description |
|---|---|---|
cacheData |
cacheData<T>(fn: (signal: AbortSignal) => Promise<T>, options: CacheDataOptions): Promise<T> |
Returns the cached value for the key, or runs fn and stores its result. fn receives the signal of the shared run (see CacheDataOptions.signal); a function that ignores it is fine. |
cachedFetch |
cachedFetch<T = unknown>( input: string | URL, init: CachedFetchInit | undefined, options: CachedFetchOptions, ): Promise<T> |
Fetches a GET URL through the cache; a JSON answer is parsed. Public data only (see the guide). |
purgeTag |
purgeTag(tag: string): Promise<void> |
Removes every entry indexed under the tag. |
inFlight |
readonly inFlight: number |
Runs in flight (for tests and diagnostics). |