Skip to content

Commit e5449b3

Browse files
committed
fix: useClones = false
1 parent c874b89 commit e5449b3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const debug = require('debug')('mysql2-cache')
1212
const mysql = require('mysql2')
1313
const crypto = require('node:crypto')
1414
const 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

1720
const { Console } = require('console')
1821
const { 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

Comments
 (0)