A flexible cache wrapper around fetch that allows you to plug in any fetch implementation (e.g., node-fetch) and any cache backend (e.g., Redis, in-memory). Current stable version is 2.0.3. Releases are infrequent. Key differentiators: the cache interface is simple (get/set returning Promises), and cached responses are rehydrated with ok, url, status, statusText, .json(), and .text() methods. It does not ship its own caching logic but instead delegates to user-provided store.
npm install fetch-cachedNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows a minimal setup using an in-memory cache with node-fetch; includes async/await usage.
Only use .json() or .text() on cached responses; avoid using .headers or .body.
Use node-fetch v3 (ESM-only) or native fetch in Node 18+. Adjust imports accordingly.
Implement your own cache key logic by wrapping the fetch function if request-specific caching is needed.
Use fetchCached(options) directly without 'new'.
Use default import: import fetchCached from 'fetch-cached'
Ensure you call .json() only once on a cached response; do not attempt to use .headers or .body.
Pass a fetch function (e.g., node-fetch) as the fetch option.