Skip to content

Instantly share code, notes, and snippets.

App::error(function(Exception $exception, $code)
{
$qs = @Input::all();
statsWrite::logError($exception,$qs);
});
var Memcached = require('memcached');
var memcached = new Memcached('memcacheserver:11211');
var Cache = {}
Cache.add = function (key, value, lifetime) {
memcached.set(key, value, lifetime);
};
Cache.get = function (key) {
Cache.get = function (key) {
memcached.get(key, function (err, data) {
console.log(data);
});
};
Cache.add = function (key, value, lifetime) {
memcached.set(key, value, lifetime, function (err){
if (err) console.warn(err)
});;
};
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.remember = function (key, lifetime, callback) {
memcached.get(key, function (err, data) {
if(data){
return data;
}
});
}
};
Cache.remember = function (key, lifetime, callback) {
return Promise.try(() => {
return memcached.getAsync(key);
}).then((value) => {
if (value !== undefined) {
return value;
} else {
return Promise.try(() => {
return callback()
}).then((value) => {
val = cache.remember('key','value1',600,function(){
return 'value2';
});
console.log('set: '+val)
Cache.remember = function (key, lifetime, callback) {
return Promise.try(() => {
return memcached.getAsync(key);
}).then((value) => {
if (value !== undefined) {
console.log('exists');
return value;
} else {
return Promise.try(() => {
if (typeof callback === "function") {
mysql.MobileAction.findOne({ where: {action_id: req.query.D} }).then(function(action) {
cache.remember('key1', 600, function() {
return Promise.resolve(action);
}).then((val) => {
console.log('set: ', val);
})
})