dnscache is an unmaintained Node.js module (last published 7 years ago, current version 1.0.2) that transparently wraps the built-in `dns` module to provide an application-level caching layer for DNS lookup results. It operates on a GOF Proxy design pattern, intercepting all `require('dns')` calls to cache frequently accessed domain resolutions, aiming to reduce network latency and improve application performance. It offers configurable cache size and Time-To-Live (TTL) settings, and supports injecting a custom cache implementation. While it historically addressed Node.js's lack of built-in DNS caching, it is now largely superseded by more modern, actively maintained libraries and evolving Node.js DNS behaviors. There is no active release cadence, and it does not support modern ECMAScript Modules (ESM) syntax.
npm install dnscacheVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to enable `dnscache` and use both the `dnscache` instance and the wrapped `dns` module for hostname lookups, showcasing the transparent caching mechanism.
Consider migrating to actively maintained DNS caching libraries like `cacheable-lookup` or application-level DNS resolution solutions (e.g., `tangerine`) that are compatible with modern Node.js versions and ESM, or leverage system-level DNS caching solutions.
Always handle errors as the first argument in callback functions when using `dnscache` (e.g., `function(err, result) { if (err) { /* handle error */ } }`). Review your error handling logic for any code paths that might rely on synchronous `dns` throws.Carefully configure the `ttl` based on the expected volatility of your target domains' DNS records. Lower TTLs offer better consistency but might increase cache misses. Ensure proper monitoring for DNS resolution failures.
Use CommonJS `require` syntax: `const dnscache = require('dnscache');`Check network connectivity and DNS server configuration. If suspecting stale cache, reduce `ttl` or explicitly clear the cache if the library supports it (though `dnscache` does not expose a public cache clearing API, it relies on TTL expiration). The library configuration includes `ttl` and `cachesize` parameters.
Ensure `dnscache` methods are used with callbacks, e.g., `dnscache.lookup('host', (err, result) => { /* handle */ });`. If you need Promise-based DNS resolution, consider `node:dns/promises` or other modern alternatives.No dependency data recorded yet.