Configure CacheableLookup options
masterWhen instantiating new CacheableLookup(options), you can provide several configuration options to control caching behavior:
cache: AMaporKeyvinstance used for storage. Default isnew Map().- Tip: Use
QuickLRUfor a Map-compatible way to limit cache size.
- Tip: Use
maxTtl: The maximum lifetime of entries in seconds. Default isInfinity. Setting to0disables caching.fallbackDuration: Time in seconds to usedns.lookup()directly when the DNS server returnsENOTFOUNDorENODATA. Default is3600.errorTtl: How long to remember queries that threwENOTFOUNDorENODATAin seconds. Default is0.15.resolver: Adns.Resolverordns.promises.Resolverinstance. Default isnew dns.promises.Resolver().lookup: The fallback function to use when the DNS server responds withENOTFOUNDorENODATA. Default isdns.lookup. If you don't query internal hostnames, it is recommended to set this tofalse.
import http from 'node:http';
import CacheableLookup from 'cacheable-lookup';
import QuickLRU from 'quick-lru';
const cacheable = new CacheableLookup({
cache: new QuickLRU({maxSize: 1000})
});
http.get('http://example.com', {lookup: cacheable.lookup}, response => {
// Handle the response here
});