Created
December 6, 2009 11:43
-
-
Save ThisIsMissEm/250176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SessionManager.prototype.cleanup = function(){ | |
var sessionExpiration, | |
now = Date.now(), | |
next = Infinity; | |
sys.log("--- Cleaning Up. SessionStore Length:"+ size(this._sessionStore)); | |
for(var sid in this._sessionStore){ | |
if(Object.prototype.hasOwnProperty.call(this._sessionStore, sid)){ | |
sessionExpiration = this._sessionStore[sid].expires; | |
sys.log("--- Checking: "+sid+": "+(sessionExpiration-now)); | |
if(sessionExpiration < now){ | |
sys.log(">>> Removing: "+sid+": "+(sessionExpiration-now)); | |
//delete this._sessionStore[sid]; | |
} else { | |
next = next > sessionExpiration-now ? sessionExpiration-now : next; | |
sys.log("--- Next Cleanup changed to "+next); | |
} | |
} | |
} | |
sys.log("+++ Cleaned Up. SessionStore Length:"+ size(this._sessionStore)); | |
if(next < Infinity){ | |
sys.log(">>> Next Cleanup in: "+next); | |
setTimeout(this.cleanup, next); | |
} else { | |
sys.log(">>> No More Cleanups. "); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node demo.js | |
06/11/2009 22:42:39:0365 >>> Created Session: QM48QsY4wYgcQAo80Y8IoY4s Expires: 06/11/2009 22:42:49:0362 | |
06/11/2009 22:42:39:0366 --- Cleaning Up. SessionStore Length:1 | |
06/11/2009 22:42:39:0366 --- Checking: QM48QsY4wYgcQAo80Y8IoY4s: 9996 | |
06/11/2009 22:42:39:0366 --- Next Cleanup changed to 9996 | |
06/11/2009 22:42:39:0366 +++ Cleaned Up. SessionStore Length:1 | |
06/11/2009 22:42:39:0366 >>> Next Cleanup in: 9996 | |
06/11/2009 22:42:49:0359 --- Cleaning Up. SessionStore Length:0 | |
06/11/2009 22:42:49:0360 +++ Cleaned Up. SessionStore Length:0 | |
06/11/2009 22:42:49:0360 >>> No More Cleanups. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment