Refactoring

This commit is contained in:
2015-09-17 17:29:59 +02:00
parent 6a790cc5bd
commit 383f70f7f3
9 changed files with 49 additions and 37 deletions

View File

@ -1,3 +1,4 @@
var crypto = require('crypto');
function Cache() {
this._store = {};
@ -20,14 +21,9 @@ Cache.prototype._serialize = function(mixedKey) {
};
Cache.prototype._hash = function(str) {
var hash = 0, i, chr, len;
if (str.length === 0) return hash;
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
var shasum = crypto.createHash('md5');
shasum.update(str);
return shasum.digest('hex');
};
module.exports = Cache;