evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a fetch wrapper that persists GET/HEAD responses on disk and honors fetch-style cache modes so callers can reuse cached content, refresh it, or fail fast when offline.
Use the dependency's disk-backed caching behavior instead of writing custom cache files.
export function createCachedFetcher(config)
/**
* @typedef {Object} CacheConfig
* @property {string} cacheDirectory - Folder for the persistent HTTP cache.
* @property {"default"|"reload"|"no-cache"|"force-cache"|"only-if-cached"} [defaultCacheMode]
* @property {string} [baseUrl]
*
* @typedef {Object} CachedFetchOptions
* @property {"default"|"reload"|"no-cache"|"force-cache"|"only-if-cached"} [cacheMode]
* @property {Object.<string, string>} [headers]
*
* @typedef {Object} CachedResponse
* @property {number} status
* @property {Object.<string, string>} headers
* @property {boolean} fromCache
* @property {() => Promise<string>} text
*
* @param {CacheConfig} config
* @returns {(url: string, options?: CachedFetchOptions) => Promise<CachedResponse>}
*/Fetch-compatible HTTP client with persistent disk cache, cache mode support, and conditional request handling.