xen-orchestra/@vates/cached-dns.lookup
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
..
.npmignore feat(@vates/cached-dns.lookup): small DNS cache (#6196) 2022-04-22 15:27:41 +02:00
.USAGE.md feat(@vates/cached-dns.lookup): small DNS cache (#6196) 2022-04-22 15:27:41 +02:00
index.js fix(cached-dns.lookup): don't use assert/strict 2022-04-24 15:28:30 +02:00
package.json feat: technical release (#6209) 2022-04-28 16:28:24 +02:00
README.md docs: uniformize code blocks 2023-02-06 11:25:12 +01:00

@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