11import dns from 'dns' ;
2- import LRU from 'lru-cache' ;
2+ import { LRUCache } from 'lru-cache' ;
33import retry , { Options as RetryOptions } from 'async-retry-ng' ;
44import resolve4 from './resolve4' ;
55import resolve6 from './resolve6' ;
66
77const lruOptions = { max : 500 } ;
8- let cache4 : LRU < string , string | Promise < string > > ;
9- let cache6 : LRU < string , string | Promise < string > > ;
8+ let cache4 : LRUCache < string , string | Promise < string > > ;
9+ let cache6 : LRUCache < string , string | Promise < string > > ;
1010
1111export const localhostRegex = / (?: \. | ^ ) l o c a l h o s t \. ? $ /
1212
@@ -49,7 +49,7 @@ export default async function dnsResolve(host: string, options: Options = {}) {
4949 }
5050
5151 if ( refreshCache ) {
52- cache . del ( host ) ;
52+ cache . delete ( host ) ;
5353 } else {
5454 const ip = cache . get ( host ) ;
5555 if ( ip ) return await ip ;
@@ -62,15 +62,15 @@ export default async function dnsResolve(host: string, options: Options = {}) {
6262 throw new DNSError ( 'ENOTFOUND' , host ) ;
6363 }
6464 const ttl = Math . max ( rec . ttl , minimumCacheTime ) ;
65- cache . set ( host , rec . address , ttl * 1000 ) ;
65+ cache . set ( host , rec . address , { ttl : ttl * 1000 } ) ;
6666 return rec . address ;
6767 } ) ( ) ;
6868
69- cache . set ( host , p , 5000 ) ;
69+ cache . set ( host , p , { ttl : 5000 } ) ;
7070 return p ;
7171}
7272
7373export function setupCache ( ) {
74- cache4 = new LRU ( lruOptions ) ;
75- cache6 = new LRU ( lruOptions ) ;
74+ cache4 = new LRUCache ( lruOptions ) ;
75+ cache6 = new LRUCache ( lruOptions ) ;
7676}
0 commit comments