Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3bd245f

Browse files
fungiboletussindresorhus
authored andcommittedFeb 26, 2021
Instantiate CacheableLookup only when needed (#1529)
1 parent a72ed84 commit 3bd245f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎source/core/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import normalizePromiseArguments from '../as-promise/normalize-arguments';
3131
import {PromiseOnly} from '../as-promise/types';
3232
import calculateRetryDelay from './calculate-retry-delay';
3333

34-
const globalDnsCache = new CacheableLookup();
34+
let globalDnsCache: CacheableLookup;
3535

3636
type HttpRequestFunction = typeof httpRequest;
3737
type Error = NodeJS.ErrnoException;
@@ -1762,6 +1762,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
17621762

17631763
// `options.dnsCache`
17641764
if (options.dnsCache === true) {
1765+
if (!globalDnsCache) {
1766+
globalDnsCache = new CacheableLookup();
1767+
}
1768+
17651769
options.dnsCache = globalDnsCache;
17661770
} else if (!is.undefined(options.dnsCache) && !options.dnsCache.lookup) {
17671771
throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is(options.dnsCache)}`);

0 commit comments

Comments
 (0)
Please sign in to comment.