Request: How to use dnscache with request?

Created on 10 Feb 2017  ·  3Comments  ·  Source: request/request

I've read through everything I can find in the backlog of issues and don't see a reference to how to do dns caching instead of resolving dns every time. There are modules already out that do the dns lookup caching already, but I can't figure out how to make request use them.

Specifically we are seeing random dns.lookup calls that can take seconds due to network latency. Ideally would like to put something in front of requests call to dns.lookup and have it provide the cached result if/when slowdown occur.

Any ideas?

stale

Most helpful comment

I just did so local fiddling to verify, and it looks like since yahoo/dnscache modifies the global DNS module, using it anywhere in your node app _should_ work across all of your HTTP requests, including those done via requestjs.

So the answer is probably as simple as just adding this anywhere in your app:

require('dnscache')({ enable: true });

...should be all it takes.

All 3 comments

You'll have to install a DNS caching server like dnsmasq, powerdns, unbound etc., and change /etc/resolv.conf to point to the DNS server IP.

I just did so local fiddling to verify, and it looks like since yahoo/dnscache modifies the global DNS module, using it anywhere in your node app _should_ work across all of your HTTP requests, including those done via requestjs.

So the answer is probably as simple as just adding this anywhere in your app:

require('dnscache')({ enable: true });

...should be all it takes.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reconbot picture reconbot  ·  86Comments

warpdesign picture warpdesign  ·  29Comments

novellizator picture novellizator  ·  25Comments

raeesaa picture raeesaa  ·  29Comments

Areks picture Areks  ·  77Comments