big refactor

This commit is contained in:
Chris Ham
2018-10-01 21:10:06 -07:00
parent e3d9ce1f62
commit 9a24f4b522
6 changed files with 611 additions and 513 deletions

View File

@@ -3,13 +3,10 @@ module.exports = {
set: placeOnCooldown
};
const memcache = require('memcache'),
md5 = require('md5'),
keyPrefix = 'cd';
const cache = new memcache.Client();
cache.on('error', console.error);
cache.connect();
const NodeCache = require('node-cache');
const cache = new NodeCache({checkperiod: 1});
const md5 = require('md5');
const keyPrefix = 'cd';
// Given a cooldownTime in seconds and a command, returns false if the command is not on cooldown
// returns the time in seconds until the command will be ready again otherwise
@@ -40,9 +37,9 @@ function isOnCooldown(command, cooldownTime, callback)
function placeOnCooldown(command, cooldownTime)
{
let key = keyPrefix + md5(command);
return cache.set(key, Date.now(), handleCacheSet, cooldownTime);
return cache.set(key, Date.now(), cooldownTime, handleCacheSet);
}
function handleCacheSet(error, result) {}
process.on('exit', (code) => {cache.close()});
process.on('exit', (code) => {cache.close()});