Skip to content

Instantly share code, notes, and snippets.

@hmpmarketing
Created January 5, 2018 17:40
Show Gist options
  • Save hmpmarketing/e85b85266d43d20f83b3834ff1d64a02 to your computer and use it in GitHub Desktop.
Save hmpmarketing/e85b85266d43d20f83b3834ff1d64a02 to your computer and use it in GitHub Desktop.
const Memcached = require('memcached');
const memcached = new Memcached('server.com:11211');
memcached.on('issue', details => console.log('issue: ', details))
memcached.on('failure', details => console.log('failure: ', details))
memcached.on('reconnecting', details => console.log('reconnecting: ', details))
memcached.on('reconnect', details => console.log('reconnect: ', details))
memcached.on('remove', details => console.log('remove: ', details))
const Cache = {}
Cache.add = function (key, value, lifetime) {
memcached.set(key, value, lifetime, function (err){
if (err) console.warn(err)
});
};
Cache.get = function (key) {
memcached.get(key, function (err, data) {
if (err) console.warn(err)
console.log(data);
});
};
module.exports = Cache;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment