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 getCache(req) {
const key = cacheKey(req);
const data = cache.get(key);
debug("getting cache key: " + key);
debug(data);
return data;
}
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);
});
};
async function getWargamingData({ url, fields, cacheKey, parseDataCb }) {
let data = cache.get(cacheKey)
if(data === null){
data = await requestWargamingData(url, fields, parseDataCb);
cache.put(cacheKey, data, CACHE_EXPIRE)
}
return data;
}
router.get('/api/machines', function(req, res) {
var machines = cache.get('machines') || [];
res.json(machines);
});