Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
request(options, (err, resp, body) => {
if (err || resp.statusCode >= 400) {
return reject(resp && resp.statusCode ? { statusCode: resp.statusCode, data: body } : { statusCode: 500, data: err });
}
cache.put(req.cookies.SESSION, JSON.stringify(body), config.web.cacheTime); // Cache the response for the next 2000 ms
return resolve(body);
});
})
res.render('subscription/widget-subscribe', data, (err, html) => {
if (err) {
return sendError(err);
}
let response = {
data: {
title: data.title,
cid: data.cid,
html
}
};
cache.put(req.path, response, 30000); // ms
res.status(200).json(response);
});
});
toCache : function(entry, data, all){
// TODO: Respect cache headers from response
var time = (entry.cache || 60 * 60 * 24) * 1000
, max = 2147483647 // http://stackoverflow.com/questions/3468607
, key = this.hash(entry, all);
time = time > max ? max : time;
cache.put(key, data, time);
return true;
},
hash : function(){
function setCache(req, data) {
const key = cacheKey(req);
debug("setting cache key: " + key);
debug(data);
return cache.put(key, data, 1000 * (60 * 60));
}
res.end = (body, encoding) => {
let toCache = {body, headers:res.header()._headers};
memCache.put(req.cacheKey, toCache, cacheTime)
return origEnd(body, encoding);
}
next();
constructor() {
if (_.isNull(Cache.get('config'))) {
Cache.put('config', this.raw());
}
}
fleet.fc.list_machines(function(err, machines){
if(err) {
log.error({err: err}, 'Error - Fleetctl: listMachines');
cache.del('machines');
}
else if(machines) {
log.debug({data: machines}, 'Fleetctl: listMachines');
cache.put('machines', machines);
}
callback(null);
});
};
.then(body => {
if (!body || !body.length) {
const error = {
message: `"${value}" for "${component.label || component.key}" is not a valid selection.`,
path: state.path,
type: 'any.select'
};
cache.put(cacheKey, error, cacheTime);
return resolve(error);
}
cache.put(cacheKey, true, cacheTime);
return resolve(null);
})
.catch(result => {
gplus.activities.list(opts, function(err, posts) {
if (err) return handleError(err, res);
var data = posts;
cache.put(cacheKey, data, DEFAULT_CACHE_MSEC);
res.json(data);
});
}