Skip to content

Commit 2c3c858

Browse files
authored
fix: resolve LRU conflicts, cache loss and premature engine breaking change (#2988)
* fix: resolve LRU conflicts and unintentional engine breaking change * chore: update lru.min * chore: update lru.min * chore: update lru.min * chore: update lru.min
1 parent 0b01333 commit 2c3c858

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

lib/connection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const EventEmitter = require('events').EventEmitter;
2222
const Readable = require('stream').Readable;
2323
const Queue = require('denque');
2424
const SqlString = require('sqlstring');
25-
const LRU = require('lru-cache').default;
25+
const { createLRU } = require('lru.min');
2626

2727
const PacketParser = require('./packet_parser.js');
2828
const Packets = require('./packets/index.js');
@@ -75,9 +75,9 @@ class Connection extends EventEmitter {
7575
this._command = null;
7676
this._paused = false;
7777
this._paused_packets = new Queue();
78-
this._statements = new LRU({
78+
this._statements = createLRU({
7979
max: this.config.maxPreparedStatements,
80-
dispose: function(statement) {
80+
onEviction: function(_, statement) {
8181
statement.close();
8282
}
8383
});
@@ -411,7 +411,7 @@ class Connection extends EventEmitter {
411411
err.code = code || 'PROTOCOL_ERROR';
412412
this.emit('error', err);
413413
}
414-
414+
415415
get fatalError() {
416416
return this._fatalError;
417417
}

lib/parsers/parser_cache.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
const LRU = require('lru-cache').default;
3+
const { createLRU } = require('lru.min');
44

5-
let parserCache = new LRU({
5+
const parserCache = createLRU({
66
max: 15000,
77
});
88

@@ -51,7 +51,7 @@ function getParser(type, fields, options, config, compiler) {
5151
}
5252

5353
function setMaxCache(max) {
54-
parserCache = new LRU({ max });
54+
parserCache.resize(max);
5555
}
5656

5757
function clearCache() {

lib/parsers/string.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

33
const Iconv = require('iconv-lite');
4-
const LRU = require('lru-cache').default;
4+
const { createLRU } = require('lru.min');
55

6-
const decoderCache = new LRU({
6+
const decoderCache = createLRU({
77
max: 500,
88
});
99

package-lock.json

Lines changed: 17 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"generate-function": "^2.3.1",
6464
"iconv-lite": "^0.6.3",
6565
"long": "^5.2.1",
66-
"lru-cache": "^8.0.0",
66+
"lru.min": "^1.0.0",
6767
"named-placeholders": "^1.1.3",
6868
"seq-queue": "^0.0.5",
6969
"sqlstring": "^2.3.2"

0 commit comments

Comments
 (0)