diff --git a/lib/connection.js b/lib/connection.js index 113fc7d46c..af6b3d9d68 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -22,7 +22,7 @@ const EventEmitter = require('events').EventEmitter; const Readable = require('stream').Readable; const Queue = require('denque'); const SqlString = require('sqlstring'); -const LRU = require('lru-cache').default; +const { createLRU } = require('lru.min'); const PacketParser = require('./packet_parser.js'); const Packets = require('./packets/index.js'); @@ -75,9 +75,9 @@ class Connection extends EventEmitter { this._command = null; this._paused = false; this._paused_packets = new Queue(); - this._statements = new LRU({ + this._statements = createLRU({ max: this.config.maxPreparedStatements, - dispose: function(statement) { + onEviction: function(_, statement) { statement.close(); } }); @@ -411,7 +411,7 @@ class Connection extends EventEmitter { err.code = code || 'PROTOCOL_ERROR'; this.emit('error', err); } - + get fatalError() { return this._fatalError; } diff --git a/lib/parsers/parser_cache.js b/lib/parsers/parser_cache.js index d85fabecce..2dd6891d91 100644 --- a/lib/parsers/parser_cache.js +++ b/lib/parsers/parser_cache.js @@ -1,8 +1,8 @@ 'use strict'; -const LRU = require('lru-cache').default; +const { createLRU } = require('lru.min'); -let parserCache = new LRU({ +const parserCache = createLRU({ max: 15000, }); @@ -51,7 +51,7 @@ function getParser(type, fields, options, config, compiler) { } function setMaxCache(max) { - parserCache = new LRU({ max }); + parserCache.resize(max); } function clearCache() { diff --git a/lib/parsers/string.js b/lib/parsers/string.js index 47c9bfa8a0..2368e5046c 100644 --- a/lib/parsers/string.js +++ b/lib/parsers/string.js @@ -1,9 +1,9 @@ 'use strict'; const Iconv = require('iconv-lite'); -const LRU = require('lru-cache').default; +const { createLRU } = require('lru.min'); -const decoderCache = new LRU({ +const decoderCache = createLRU({ max: 500, }); diff --git a/package-lock.json b/package-lock.json index aaba6ee19f..218446eeb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", "long": "^5.2.1", - "lru-cache": "^8.0.0", + "lru.min": "^1.0.0", "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" @@ -2156,12 +2156,19 @@ "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, - "node_modules/lru-cache": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.4.tgz", - "integrity": "sha512-E9FF6+Oc/uFLqZCuZwRKUzgFt5Raih6LfxknOSAVTjNkrCZkBf7DQCwJxZQgd9l4eHjIJDGR+E+1QKD1RhThPw==", + "node_modules/lru.min": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.0.0.tgz", + "integrity": "sha512-YthLl3hdewA3lIwPrpgDLNlq6bvgbZjJQR4qr6oQ2c6lC78sCOwJkn0AkuUArbydQNQ+PjwIVz9IwZNrmLhXeg==", + "license": "MIT", "engines": { - "node": ">=16.14" + "bun": ">=1.0.0", + "deno": ">=1.30.0", + "node": ">=8.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" } }, "node_modules/make-dir": { @@ -4944,10 +4951,10 @@ "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, - "lru-cache": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-8.0.4.tgz", - "integrity": "sha512-E9FF6+Oc/uFLqZCuZwRKUzgFt5Raih6LfxknOSAVTjNkrCZkBf7DQCwJxZQgd9l4eHjIJDGR+E+1QKD1RhThPw==" + "lru.min": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lru.min/-/lru.min-1.0.0.tgz", + "integrity": "sha512-YthLl3hdewA3lIwPrpgDLNlq6bvgbZjJQR4qr6oQ2c6lC78sCOwJkn0AkuUArbydQNQ+PjwIVz9IwZNrmLhXeg==" }, "make-dir": { "version": "4.0.0", diff --git a/package.json b/package.json index a409638902..0ee7fc343b 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "generate-function": "^2.3.1", "iconv-lite": "^0.6.3", "long": "^5.2.1", - "lru-cache": "^8.0.0", + "lru.min": "^1.0.0", "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2"