createDataCache
Creates a data cache over a store.
Creates a data cache over a store. The request-bound functions cacheData and cachedFetch use the cache of the handler that serves the request; this function is for a store of your own (a script, a test, a worker).
Import#
ts
import { createDataCache } from "@shadow-js/dusk/server";
Signature#
ts
function createDataCache(options: DataCacheOptions): DataCache
Parameters#
| Name | Description |
|---|---|
options |
The store and the settings. |
Returns#
The cache.
Throws#
- RangeError / TypeError for a bad bound or profile.
Examples#
ts
const cache = createDataCache({ kv: createMemoryKVStore() });
await cache.cacheData(() => loadPosts(), { key: ["posts"], revalidate: 60, tags: ["posts"] });