@@ -4,8 +4,8 @@ var Tls = require('tls');
4
4
var Timers = require ( 'timers' ) ;
5
5
var EventEmitter = require ( 'events' ) . EventEmitter ;
6
6
var Queue = require ( 'double-ended-queue' ) ;
7
-
8
7
var SqlString = require ( 'sqlstring' ) ;
8
+ var LRU = require ( 'lru-cache' ) ;
9
9
10
10
var PacketParser = require ( './packet_parser.js' ) ;
11
11
var Packet = require ( './packets/packet.js' ) ;
@@ -51,7 +51,10 @@ function Connection (opts)
51
51
this . _paused = false ;
52
52
this . _paused_packets = new Queue ( ) ;
53
53
54
- this . _statements = { } ;
54
+ this . _statements = LRU ( {
55
+ max : 1000 ,
56
+ dispose : function ( key , statement ) { statement . close ( ) ; }
57
+ } ) ;
55
58
56
59
// TODO: make it lru cache
57
60
// https://github.com/mercadolibre/node-simple-lru-cache
@@ -498,9 +501,9 @@ Connection.prototype.unprepare = function unprepare (sql) {
498
501
options . sql = sql ;
499
502
}
500
503
var key = statementKey ( options ) ;
501
- var stmt = this . _statements [ key ] ;
504
+ var stmt = this . _statements . get ( key ) ;
502
505
if ( stmt ) {
503
- this . _statements [ key ] = null ;
506
+ this . _statements . del ( key ) ;
504
507
stmt . close ( ) ;
505
508
}
506
509
return stmt ;
@@ -531,7 +534,7 @@ Connection.prototype.execute = function execute (sql, values, cb) {
531
534
532
535
var connection = this ;
533
536
var key = statementKey ( options ) ;
534
- var statement = connection . _statements [ key ] ;
537
+ var statement = connection . _statements . get ( key ) ;
535
538
536
539
options . statement = statement ;
537
540
var executeCommand = new Commands . Execute ( options , cb ) ;
@@ -547,7 +550,7 @@ Connection.prototype.execute = function execute (sql, values, cb) {
547
550
return ;
548
551
}
549
552
executeCommand . statement = stmt ;
550
- connection . _statements [ key ] = stmt ;
553
+ connection . _statements . set ( key , stmt ) ;
551
554
connection . addCommand ( executeCommand ) ;
552
555
} ) ;
553
556
} else {
0 commit comments