https://github.com/microlinkhq/ping-url
Fast DNS resolution caching results for a while.
https://github.com/microlinkhq/ping-url
Last synced: 10 months ago
JSON representation
Fast DNS resolution caching results for a while.
- Host: GitHub
- URL: https://github.com/microlinkhq/ping-url
- Owner: microlinkhq
- License: mit
- Created: 2019-10-23T19:39:20.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-08T08:28:26.000Z (about 2 years ago)
- Last Synced: 2025-07-24T15:18:53.000Z (11 months ago)
- Language: JavaScript
- Size: 139 KB
- Stars: 9
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README

[](https://coveralls.io/github/microlinkhq/ping-url)
[](https://www.npmjs.org/package/@microlink/ping-url)
> Fast DNS resolution caching results for a while.
## Motivation
Ping an URL for getting the canonical URL and store the result into a cache, respecting a Time-to-Live (*TTL*) for the next lookup.
Suggested TTL could be:
- **Very Short**: 300 seconds (5 minutes).
- **Short**: 3600 seconds (1 hour).
- **Long**: 86400 seconds (24 hours).
- **Insanity**: 604800 seconds (7 days).
This library support any data storage provided by [`keyv`](https://npm.im/keyv).
## Install
```bash
$ npm install @microlink/ping-url --save
```
## Usage
```js
const createPingUrl = require('@microlink/ping-url')
const cache = new Map()
const pingUrl = createPingUrl({ store: cache, ttl: 3600 })
;(async () => {
await pingUrl('https://example.com') // MISS, do the request
await pingUrl('https://example.com') // HIT, serve from cache!
})()
```
The payload returned by `pingUrl` will be `response` but without any stream object there.
## API
### createPingUrl([keyvOptions], [memoOpts]) → pingUrl(url, [gotOpts])
#### keyvOptions
See [`keyv#options`](https://www.npmjs.com/package/keyv#new-keyvuri-options).
#### memoOpts
See [`@keyvhq/memoize`](https://github.com/microlinkhq/keyv/tree/master/packages/memoize).
#### gotOpts
Type: `object`
Any option provided here will passed to [got#options](https://github.com/sindresorhus/got#options).
## License
**@microlink/ping-url** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlink/ping-url/blob/master/LICENSE.md) License.
Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlink/ping-url/contributors).
> [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · Twitter [@microlinkhq](https://twitter.com/microlinkhq)