Cross-platform fetch wrapper that adds HTTP caching support to any fetch implementation using a key-value cache. Version 0.1.6 is the latest stable release. It follows HTTP Caching (RFC 7234) and Conditional Requests (RFC 7232) standards, allowing server-like caching behavior in non-browser environments (Node.js, workers). Unlike simple memoization, it respects Cache-Control headers, ETags, and expiration. Ships TypeScript types. Requires Node >= 16. Low release cadence; maintained by Ardatan/whatwg-node ecosystem.
npm install fetchacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a cached fetch using an in-memory Map, demonstrating the minimal setup with @whatwg-node/fetch.
Always pass both fetch and Response. Use @whatwg-node/fetch for Node.js.
Implement cache { get(key: string): Promise<string|undefined>; set(key: string, value: string): Promise<void> }.Use import syntax or dynamic import(). Set 'type':'module' in package.json if running as CommonJS.
Understand that cache keys are derived from the request; do not rely on manual key generation.
Use @whatwg-node/fetch which exports a constructor-compatible fetch. Alternatively, wrap fetch using the factory pattern: const fetchFunc = (...args) => fetch(...args);
Change to import { fetchFactory } from 'fetchache' or use dynamic import().Ensure cache implements { get: (key: string) => Promise<string | undefined> }.