-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
checkperiod only trigger once? #78
Comments
probably your script will just end before your defined ttl's expire. You can just run your own timeout like this example: var node_cache = require("node-cache");
var myCache = new node_cache( { stdTTL: 50, checkperiod: 2 } );
myCache.set("A:1", 123, 5);
myCache.set("A:2", 456, 10);
myCache.on("expired", function( key, value ){
console.log(key + " is expired");
// ... do something ...
});
console.log( "waiting ... " );
// add a timeout to prevent the script to exit
setTimeout( function( ){
console.log( "exit" );
}, 15000 )
|
Yes, I put the code to runkit is work well, but it is doesn't work on my 2 linux machine, Do you try the code on real machine? Ubuntu 14.04 x64 |
i tested some environments with docker. The only case i found your problem is Which Node version do you use?
|
I tried update nodejs to v6.9.2, it is work well, but it is not default for Ubuntu apt-get install, so I look into the code of node-cache, the checkTimeout without parameters, so default parameter will be 0 on nodejs 0.10.25, cause startPeriod = 0 on 2nd time, it is will not create timeout again when trigger once
change to
it is work well on nodejs 0.10.25 |
I added your fix to |
I tried following code, but seems only show "A:1 is expired", "A:2" never be show
var myCache = new node_cache( { stdTTL: 50, checkperiod: 20 } );
myCache.set("A:1", Code, 10);
myCache.set("A:2", Code, 25);
myCache.on("expired", function( key, value ){
console.log(key + " is expired");
// ... do something ...
});
How can make it run the expired check by interval?
The text was updated successfully, but these errors were encountered: