Closed leiyangyou closed 3 months ago
when cacher has maxParamsLength set, if the action also specifies a keys array say ["id"], and the id is of type number, the cacher crashes upon key generation, as hashkey will pass id to crypto.createHash, the length check fails because
1.length < maxLength always fails
the following patch does the trick for now
diff --git a/node_modules/moleculer/src/cachers/base.js b/node_modules/moleculer/src/cachers/base.js index 3cee84a..06ece92 100644 --- a/node_modules/moleculer/src/cachers/base.js +++ b/node_modules/moleculer/src/cachers/base.js @@ -232,7 +232,7 @@ class Cacher { return ( keyPrefix + this._hashedKey( - isObject(val) ? this._hashedKey(this._generateKeyFromObject(val)) : val + isObject(val) ? this._hashedKey(this._generateKeyFromObject(val)) : String(val) ) ); } @@ -248,7 +248,7 @@ class Cacher { (i ? "|" : "") + (isObject(val) || Array.isArray(val) ? this._hashedKey(this._generateKeyFromObject(val)) - : val) + : String(val)) ); }, "") )
Current Behavior
when cacher has maxParamsLength set, if the action also specifies a keys array say ["id"], and the id is of type number, the cacher crashes upon key generation, as hashkey will pass id to crypto.createHash, the length check fails because
1.length < maxLength always fails
the following patch does the trick for now