Files
xen-orchestra/@vates/cached-dns.lookup/README.md
Julien Fontanet 2a70ebf667 docs: uniformize code blocks
- add missing syntaxes
- don't put prompt if no command outputs to ease copy/paste and use `sh` syntax
- always use `$` as prompt and use `console` syntax
2023-02-06 11:25:12 +01:00

2.0 KiB

@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 lead application doing a lot of connections to have perf issues and to saturate Node threads pool.

This library attempts 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.

It 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