Skip to content

microlinkhq/ping-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

170 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

microlink logo microlink logo

Last version Coverage Status NPM Status

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.

Install

$ npm install @microlink/ping-url --save

Usage

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.

memoOpts

See @keyvhq/memoize.

gotOpts

Type: object

Any option provided here will passed to got#options.

License

@microlink/ping-url © Microlink, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

microlink.io · GitHub microlinkhq · Twitter @microlinkhq

About

Fast DNS resolution caching results for a while.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •