{"library":"node-fetch-cache","title":"Node Fetch Cache","description":"node-fetch-cache is a robust wrapper around the popular `node-fetch` library, providing an integrated caching layer for HTTP responses. It automatically caches responses from HTTP requests, serving subsequent identical requests directly from the cache without making a network call. The current stable version is 5.1.0, and the project appears to have an active release cadence with regular updates and maintenance, as indicated by recent releases adding new features like cache clearing. Key differentiators include its seamless integration with the standard `node-fetch` API, support for multiple cache backends (in-memory, file system, Redis via an adapter), and flexible control over caching behavior through `shouldCacheResponse` options. It's designed for Node.js environments, requiring Node.js 18.19.0 or higher, and ships with TypeScript types for improved developer experience.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install node-fetch-cache"],"cli":null},"imports":["import fetch from 'node-fetch-cache';","import NodeFetchCache from 'node-fetch-cache';","import { FileSystemCache } from 'node-fetch-cache';","import { MemoryCache } from 'node-fetch-cache';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import fetch from 'node-fetch-cache';\nimport { FileSystemCache } from 'node-fetch-cache';\nimport * as path from 'path';\n\nasync function fetchData() {\n  // Create a custom fetch instance that caches to disk with a 1-hour TTL\n  const diskCacheFetch = NodeFetchCache.create({\n    cache: new FileSystemCache({\n      cacheDirectory: path.join(process.cwd(), '.node-fetch-cache'),\n      ttl: 3600000 // 1 hour in milliseconds\n    }),\n    shouldCacheResponse: (response) => response.ok // Only cache successful responses\n  });\n\n  console.log('Fetching Google homepage (first time - network request)...');\n  const firstResponse = await diskCacheFetch('http://google.com');\n  console.log('Status:', firstResponse.status);\n  console.log('Cached:', firstResponse.headers.get('x-nf-cache-status')); // Should be 'MISS'\n\n  console.log('\\nFetching Google homepage (second time - from cache)...');\n  const secondResponse = await diskCacheFetch('http://google.com');\n  console.log('Status:', secondResponse.status);\n  console.log('Cached:', secondResponse.headers.get('x-nf-cache-status')); // Should be 'HIT'\n\n  // Demonstrate clearing the cache\n  const fileCache = new FileSystemCache({ cacheDirectory: path.join(process.cwd(), '.node-fetch-cache') });\n  console.log('\\nClearing file system cache...');\n  await fileCache.clear();\n  console.log('Cache cleared. Subsequent fetch will be a MISS again.');\n\n  const thirdResponse = await diskCacheFetch('http://google.com');\n  console.log('Status:', thirdResponse.status);\n  console.log('Cached:', thirdResponse.headers.get('x-nf-cache-status')); // Should be 'MISS' again\n}\n\nfetchData().catch(console.error);","lang":"typescript","description":"This quickstart demonstrates how to use `node-fetch-cache` with a file system cache, including setting a TTL, filtering responses to cache, and programmatically clearing the cache directory.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}