1.0.0 • Published 2 years ago

@vates/cached-dns.lookup v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@vates/cached-dns.lookup

Package Version License PackagePhobia Node compatibility

Cached implementation of dns.lookup

Install

Installation of the npm package:

> npm install --save @vates/cached-dns.lookup

Usage

Node does not cache queries to dns.lookup, which can leads application doing a lot of connections to have perf issues and to saturate Node threads pool.

This library attemps to mitigate these problems by providing a version of this function with a version short cache, applied on both errors and results.

Limitation: verbatim: false option is not supported.

I has exactly the same API as the native method and can be used directly:

import { createCachedLookup } from '@vates/cached-dns.lookup'

const lookup = createCachedLookup()

lookup('example.net', { all: true, family: 0 }, (error, result) => {
  if (error != null) {
    return console.warn(error)
  }
  console.log(result)
})

Or it can be used to replace the native implementation and speed up the whole app:

// assign our cached implementation to dns.lookup
const restore = createCachedLookup().patchGlobal()

// to restore the previous implementation
restore()

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Vates SAS