1
- import debug from 'debug '
2
- import Receptacle from 'receptacle '
1
+ import QuickLRU from 'quick-lru '
2
+ import debug from 'weald '
3
3
import * as utils from './utils.js'
4
4
import type { DNSJSON } from './utils'
5
5
@@ -19,8 +19,8 @@ interface ResolverOptions {
19
19
* Uses a list of servers to resolve DNS records with HTTP requests.
20
20
*/
21
21
class Resolver {
22
- private readonly _cache : Receptacle < string [ ] >
23
- private readonly _TXTcache : Receptacle < string [ ] [ ] >
22
+ private readonly _cache : QuickLRU < string , string [ ] >
23
+ private readonly _TXTcache : QuickLRU < string , string [ ] [ ] >
24
24
private _servers : string [ ]
25
25
private readonly _request : Request
26
26
private _abortControllers : AbortController [ ]
@@ -32,8 +32,8 @@ class Resolver {
32
32
* @param {Request } [options.request] - function to return DNSJSON
33
33
*/
34
34
constructor ( options : ResolverOptions = { } ) {
35
- this . _cache = new Receptacle ( { max : options ?. maxCache ?? 100 } )
36
- this . _TXTcache = new Receptacle ( { max : options ?. maxCache ?? 100 } )
35
+ this . _cache = new QuickLRU ( { maxSize : options ?. maxCache ?? 100 } )
36
+ this . _TXTcache = new QuickLRU ( { maxSize : options ?. maxCache ?? 100 } )
37
37
this . _servers = [
38
38
'https://cloudflare-dns.com/dns-query' ,
39
39
'https://dns.google/resolve'
@@ -133,7 +133,7 @@ class Resolver {
133
133
const data = response . Answer . map ( a => a . data )
134
134
const ttl = Math . min ( ...response . Answer . map ( a => a . TTL ) )
135
135
136
- this . _cache . set ( utils . getCacheKey ( hostname , recordType ) , data , { ttl } )
136
+ this . _cache . set ( utils . getCacheKey ( hostname , recordType ) , data , { maxAge : ttl } )
137
137
138
138
return data
139
139
} catch ( err ) {
@@ -183,7 +183,7 @@ class Resolver {
183
183
const data = response . Answer . map ( a => a . data )
184
184
const ttl = Math . min ( ...response . Answer . map ( a => a . TTL ) )
185
185
186
- this . _cache . set ( utils . getCacheKey ( hostname , recordType ) , data , { ttl } )
186
+ this . _cache . set ( utils . getCacheKey ( hostname , recordType ) , data , { maxAge : ttl } )
187
187
188
188
return data
189
189
} catch ( err ) {
@@ -233,7 +233,7 @@ class Resolver {
233
233
const data = response . Answer . map ( a => [ a . data . replace ( / [ ' " ] + / g, '' ) ] )
234
234
const ttl = Math . min ( ...response . Answer . map ( a => a . TTL ) )
235
235
236
- this . _TXTcache . set ( utils . getCacheKey ( hostname , recordType ) , data , { ttl } )
236
+ this . _TXTcache . set ( utils . getCacheKey ( hostname , recordType ) , data , { maxAge : ttl } )
237
237
238
238
return data
239
239
} catch ( err ) {
0 commit comments