addr-to-ip-port
Advanced tools
Comparing version 1.3.0 to 1.4.0
11
index.js
@@ -5,3 +5,8 @@ var ADDR_RE = /^\[?([^\]]+)\]?:(\d+)$/ // ipv4/ipv6/hostname + port | ||
// reset cache when it gets to 100,000 elements (~ 600KB of ipv4 addresses) | ||
// so it will not grow to consume all memory in long-running processes | ||
var size = 0 | ||
module.exports = function addrToIPPort (addr) { | ||
if (size === 100000) cache = {} | ||
if (!cache[addr]) { | ||
@@ -11,2 +16,3 @@ var m = ADDR_RE.exec(addr) | ||
cache[addr] = [ m[1], Number(m[2]) ] | ||
size += 1 | ||
} | ||
@@ -19,6 +25,1 @@ return cache[addr] | ||
} | ||
// reset cache every hour so it will not grow to consume all memory | ||
// in long-running processes (like in server dameons) | ||
var interval = setInterval(module.exports.reset, 60 * 60 * 1000) | ||
if (interval.unref) interval.unref() |
{ | ||
"name": "addr-to-ip-port", | ||
"description": "Convert an 'address:port' string to an array [address:string, port:number]", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -13,5 +13,9 @@ var addrToIPPort = require('../') | ||
addrToIPPort.reset() | ||
var ipPort | ||
for (var i = 0, len = addrs.length; i < len; i++) { | ||
var ipPort = addrToIPPort(addrs[i]) | ||
ipPort = addrToIPPort(addrs[i]) | ||
} | ||
for (var i = 0, len = addrs.length; i < len; i++) { | ||
ipPort = addrToIPPort(addrs[i]) | ||
} | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5450
68
3473