Gathering detailed insights and metrics for cacheable-lookup
Gathering detailed insights and metrics for cacheable-lookup
Gathering detailed insights and metrics for cacheable-lookup
Gathering detailed insights and metrics for cacheable-lookup
@esm2cjs/cacheable-lookup
A cacheable dns.lookup(…) that respects TTL. This is a fork of szmarczak/cacheable-lookup, but with CommonJS support.
cacheable-request
Wrap native HTTP requests with RFC compliant cache support
file-entry-cache
A lightweight cache for file metadata, ideal for processes that work on a specific set of files and only need to reprocess files that have changed since the last run
flat-cache
A simple key/value storage using files to persist the data
npm install cacheable-lookup
99.2
Supply Chain
100
Quality
78.5
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
193 Stars
118 Commits
29 Forks
4 Watching
4 Branches
12 Contributors
Updated on 01 Nov 2024
JavaScript (95.48%)
TypeScript (4.52%)
Cumulative downloads
Total Downloads
Last day
-6.2%
2,211,464
Compared to previous day
Last week
3.8%
13,083,803
Compared to previous week
Last month
6.2%
53,897,078
Compared to previous month
Last year
30.4%
568,619,370
Compared to previous year
A cacheable
dns.lookup(…)
that respects TTL :tada:
Making lots of HTTP requests? You can save some time by caching DNS lookups :zap:
lookup
option1import http from 'node:http'; 2import CacheableLookup from 'cacheable-lookup'; 3 4const cacheable = new CacheableLookup(); 5 6http.get('http://example.com', {lookup: cacheable.lookup}, response => { 7 // Handle the response here 8});
1import http from 'node:http'; 2import https from 'node:https'; 3import CacheableLookup from 'cacheable-lookup'; 4 5const cacheable = new CacheableLookup(); 6 7cacheable.install(http.globalAgent); 8cacheable.install(https.globalAgent); 9 10http.get('http://example.com', response => { 11 // Handle the response here 12});
Returns a new instance of CacheableLookup
.
Type: object
Default: {}
Options used to cache the DNS lookups.
Type: Map
| Keyv
Default: new Map()
Custom cache instance. If undefined
, it will create a new one.
Note: If you decide to use Keyv instead of the native implementation, the performance will drop by 10x. Memory leaks may occur as it doesn't provide any way to remove all the deprecated values at once.
Tip: QuickLRU
is fully compatible with the Map API, you can use it to limit the amount of cached entries. Example:
1import http from 'node:http'; 2import CacheableLookup from 'cacheable-lookup'; 3import QuickLRU from 'quick-lru'; 4 5const cacheable = new CacheableLookup({ 6 cache: new QuickLRU({maxSize: 1000}) 7}); 8 9http.get('http://example.com', {lookup: cacheable.lookup}, response => { 10 // Handle the response here 11});
Type: number
Default: Infinity
The maximum lifetime of the entries received from the specifed DNS server (TTL in seconds).
If set to 0
, it will make a new DNS query each time.
Pro Tip: This shouldn't be lower than your DNS server response time in order to prevent bottlenecks. For example, if you use Cloudflare, this value should be greater than 0.01
.
Type: number
Default: 3600
(1 hour)
When the DNS server responds with ENOTFOUND
or ENODATA
and the OS reports that the entry is available, it will use dns.lookup(...)
directly for the requested hostnames for the specified amount of time (in seconds).
Note: You should avoid setting this to 0
unless the provided DNS servers' database is limited to few domains.
Type: number
Default: 0.15
The time how long it needs to remember queries that threw ENOTFOUND
or ENODATA
(TTL in seconds).
Note: This option is independent, options.maxTtl
does not affect this.
Pro Tip: This shouldn't be lower than your DNS server response time in order to prevent bottlenecks. For example, if you use Cloudflare, this value should be greater than 0.01
.
Type: dns.Resolver | dns.promises.Resolver
Default: new dns.promises.Resolver()
An instance of DNS Resolver used to make DNS queries.
Type: Function
Default: dns.lookup
The fallback function to use when the DNS server responds with ENOTFOUND
or ENODATA
.
If you don't query internal hostnames (such as localhost
, database.local
etc.), it is strongly recommended to set this to false
.
Type: object
Type: string
The IP address (can be an IPv4 or IPv6 address).
Type: number
The IP family (4
or 6
).
Type: number
Note: This is not present when falling back to dns.lookup(...)
!
The timestamp (Date.now() + ttl * 1000
) when the entry expires.
Note: This is not present when falling back to dns.lookup(...)
!
The time in seconds for its lifetime.
Note: This is not present when falling back to dns.lookup(...)
!
Whether this entry was loaded from the cache or came from a query (cache
or query
)
When options.all
is false
, then callback(error, address, family, expires, ttl)
is called.
When options.all
is true
, then callback(error, entries)
is called.
Type: Array
The DNS servers used to make queries. Can be overridden - doing so will clear the cache.
The asynchronous version of dns.lookup(…)
.
Returns an entry object.
If options.all
is true, returns an array of entry objects.
Type: string
Type: object
The same as the dns.lookup(…)
options.
An asynchronous function which returns cached DNS lookup entries.
This is the base for lookupAsync(hostname, options)
and lookup(hostname, options, callback)
.
Note: This function has no options.
Returns an array of objects with address
, family
, ttl
and expires
properties.
An asynchronous function which makes two DNS queries: A and AAAA. The result is cached.
This is used by query(hostname)
if no entry in the database is present.
Returns an array of objects with address
, family
, ttl
and expires
properties.
Updates interface info. For example, you need to run this when you plug or unplug your WiFi driver.
Note: Running updateInterfaceInfo()
will trigger clear()
only on network interface removal.
Clears the cache for the given hostname. If the hostname argument is not present, the entire cache will be emptied.
Performed on:
example.com
CacheableLookup#lookupAsync x 2,896,251 ops/sec ±1.07% (85 runs sampled)
CacheableLookup#lookupAsync.all x 2,842,664 ops/sec ±1.11% (88 runs sampled)
CacheableLookup#lookupAsync.all.ADDRCONFIG x 2,598,283 ops/sec ±1.21% (88 runs sampled)
CacheableLookup#lookup x 2,565,913 ops/sec ±1.56% (85 runs sampled)
CacheableLookup#lookup.all x 2,609,039 ops/sec ±1.01% (86 runs sampled)
CacheableLookup#lookup.all.ADDRCONFIG x 2,416,242 ops/sec ±0.89% (85 runs sampled)
dns#lookup x 7,272 ops/sec ±0.36% (86 runs sampled)
dns#lookup.all x 7,249 ops/sec ±0.40% (86 runs sampled)
dns#lookup.all.ADDRCONFIG x 5,693 ops/sec ±0.28% (85 runs sampled)
Fastest is CacheableLookup#lookupAsync.all
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More