Simple DNS cache for Node.js that automatically caches all dns.lookup calls with configurable TTL. Current stable version is 2.0.0, compatible with Node.js >=0.12.0. Version 2.0.0 is not backwards compatible with Node.js <0.12 due to changes in dns.lookup. For Node.js 0.10 and older, use version 1.0.0. This package addresses DNS lookup conflicts (see joyent/node#7729) and improves performance by reducing redundant DNS queries. It is lightweight, easy to use (just require once), and accepts a TTL in milliseconds.
npm install dns-cacheNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Enables DNS caching with a 10-second TTL and performs a lookup.
Use version 1.0.0 for Node.js 0.10 and older.
Upgrade to version 2.0.0 if using Node.js 0.12 or newer.
Monitor cache size or implement custom pruning if necessary.
Consider using scoped lookups or per-module caching if isolation is needed.
const dnscache = require('dns-cache')(ttl);Call require('dns-cache')(1000) with a numeric TTL in milliseconds.No dependency data recorded yet.