@@ -12,7 +12,10 @@ const debug = require('debug')('mysql2-cache')
1212const mysql = require ( 'mysql2' )
1313const crypto = require ( 'node:crypto' )
1414const NodeCache = require ( 'node-cache' )
15- const queryCache = new NodeCache ( { stdTTL : DEFAULT_CACHE_TTL , checkperiod : DEFAULT_CACHE_CHECKPERIOD } )
15+ // useClones = false
16+ // https://github.com/node-cache/node-cache/issues/295
17+ // https://runkit.com/mpneuried/useclones-example-83
18+ const queryCache = new NodeCache ( { stdTTL : DEFAULT_CACHE_TTL , checkperiod : DEFAULT_CACHE_CHECKPERIOD , useClones : false } )
1619
1720const { Console } = require ( 'console' )
1821const { Transform } = require ( 'stream' )
@@ -46,7 +49,7 @@ module.exports.connect = (config = {}) => {
4649 pool . q = async ( sql , params = [ ] , cache = false , ttl = undefined ) => {
4750 qid ++
4851 const log = debug . extend ( qid )
49- log ( sql , params , { cache : cache , ttl : ttl ? ttl : DEFAULT_CACHE_TTL } )
52+ log ( sql , params , { cache : cache , ttl : ttl ? ttl : DEFAULT_CACHE_TTL } )
5053 // https://medium.com/@chris_ 72272/what-is-the-fastest-node-js-hashing-algorithm-c15c1a0e164e
5154 const hash = crypto . createHash ( 'sha1' ) . update ( sql + JSON . stringify ( params ) ) . digest ( 'base64' )
5255 if ( cache && queryCache . has ( hash ) ) {
0 commit comments