-
Notifications
You must be signed in to change notification settings - Fork 145
Description
Hi
This is a specific case when deleteOnExpire:false and try to use has/get function in .on("expired", (key,value) => callback)
Here is a small sample code to test the behaviour
import NodeCache from 'node-cache';
const myCache = new NodeCache({checkperiod:10,deleteOnExpire:false});
myCache.on( "set", ( key, value ) => console.log("On SET "+ key + '=' + value));
myCache.on( "del", ( key, value ) => console.log("On DEL: "+ key + '=' + value));
myCache.on( "expired", ( key, value ) => {
console.log("On EXPIRED "+ key + '=' + value);
//myCache.set(key, value+'_',10); // <-- Uncommenting will work, commenting this line will crash process due to either of below lines causing recursion
let test1 = myCache.has(key); //<--
let test2 =myCache.get(key); // <--
});
myCache.set("MyKey","MyValue",5);
//Below code is dummy/sample long running code....
let done =1;
(function wait () {
if (done) setTimeout(wait, 1000);
})();
─$ node test.mjs
On EXPIRED MyKey=MyValue
On EXPIRED MyKey=MyValue
On EXPIRED MyKey=MyValue
....
On EXPIRED MyKey=MyValue
node:internal/console/constructor:309
if (isStackOverflowError(e))
^
RangeError: Maximum call stack size exceeded
at console.value (node:internal/console/constructor:309:13)
at console.log (node:internal/console/constructor:380:26)
at NodeCache. (file:///Users/raxitsmacbook/MyNodeRnd/test.mjs:7:10)
at NodeCache.emit (node:events:514:28)
at NodeCache._check (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:659:16)
at NodeCache.has (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:575:52)
at NodeCache. (file:///Users/raxitsmacbook/MyNodeRnd/test.mjs:9:22)
at NodeCache.emit (node:events:514:28)
at NodeCache._check (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:659:16)
at NodeCache.has (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:575:52)
Node.js v18.17.1 (However it looks like this behaviour is independent of Node version, Just in case if version can be of any help.)
Possible bug also in: mget when deleteOnExpire:false
Also when deleteOnExpire:false it constantly emits "expired" event on every 'checkperiod' times. (But it does not crash, But nice to have non-periodic expire event unless the object/key/value/expiry etc has been modified.