exports.setex = function(type,key,timeout,value){ if(value){ return cache.put(type + ':' + key,value,timeout); }else{ return cache.put(type + ':' + key,timeout); } };
rss.state(st.id, function (items) { if (items.length > 0) { // if the items in cache is different then update the cache if (JSON.stringify(items) !== JSON.stringify(cache.get(items[0].state))) { console.log('Inserting ' + items[0].state + ' into cache'); cache.put(items[0].state, items, life); } else { // update the cache console.log('Updating ' + items[0].state + ' cache'); cache.put(items[0].state, items, life); } // update or insert the individual child records cache for (var c = 0; c < items.length; c++) { var child = items[c]; var existing = cache.get(child.caseNumber); if (existing == null) { cache.put(child.caseNumber, child, life); } else { // compare to see if the obj has changed if (JSON.stringify(child) !== JSON.stringify(existing)) { cache.put(child.caseNumber, child, life); } } } } });
.action(function(client, options) { if(client) { require('../client/'+client+'/install')(function() { process.exit(); }); } else { if(options.notorrent) cache.put('notorrent', true); if(options.skipnginx) cache.put('skipnginx', true); if(options.skipuser) cache.put('skipuser', true); cache.put('isinstall', true); async.series(install, function (err, results) { require('../lib/deploy.js')(function(code) { console.log("Fin de l'installation. Lancez ezseed start".info); process.exit(0); }); } ); } });
function (err, client) { if(cache.get('notorrent') === true) { cache.put('client', 'aucun'); callback(null, 'aucun'); } else if(client == 'aucun') { promptly.confirm( "Êtes vous sûr de ne pas vouloir installer de client ? Y/n", {default : 'y'}, function (err, value) { if(value === true) { cache.put('client', 'aucun'); require('../client/aucun/install')(callback); } else return choose(callback); } ); } else { cache.put('client', client); require('../client/'+client+'/install')(callback); } });
fbRef.once("value", function(snapshot) { console.log(snapshot.val().coaches); console.log(snapshot.val().matches); cache.put('matches', snapshot.val().matches); cache.put('players', snapshot.val().players); cache.put('coaches', snapshot.val().coaches); });
function onRemoteUrlRequestComplete (err, json) { if (err) { callback(err, null); } else if (json.hosts && json.hosts.url) { log.trace('received fh3 response, returnung url "%s"', json.hosts.url); // This is for domains with multiple mbaases, e.g dev, test, staging, live cache.put(opts.guid, json.hosts.url, CACHE_TIMEOUT); callback(null, json.hosts.url); } else { // Older domains only have dev and live log.trace('received fh2 response, attempting parse for json:', json); try { var dev = json.hosts['development-url'] , live = json.hosts['live-url']; var host = (util.getEnv() === 'live') ? live : dev; cache.put(opts.guid, host, CACHE_TIMEOUT); callback(null, host); } catch (e) { callback( new VError( e, 'Unexpected JSON format from FH Instance Lookup %j', json ), null ); } } }
T.get('statuses/user_timeline', { screen_name: 'pomeo', count: 2 }, function (err, reply) { tw = twitterCall(reply); cache.put('twitter', tw, 1440000); cache.put('github', git, 1440000); res.locals.d = tw; res.locals.g = git; res.render('index', { title: 'Sergey Ovechkin' }); });
var failed = function(request) { if(typeof request === typeof 'str'){ m_cache.put(request, request); } if(typeof request === typeof {}){ m_cache.put(request.objectId, request); } };
return http.get('http://' + process.env.OPENSHIFT_NODEJS_IP + ':17000/apikey/isNoApiKeyAllowed', function (_res) { if (_res.statusCode === 200) { // allowed cache.put('NOAPIKEYALLOWED', true, validApiKeyTtl); return proxyRequest(proxy, req, res, buffer); } cache.put('NOAPIKEYALLOWED', false, validApiKeyTtl); res.send(403, 'Forbidden'); });
http.get('http://' + process.env.OPENSHIFT_NODEJS_IP + ':17000/apikey/' + key, function (_res) { if (_res.statusCode === 200) { // valid key cache.put(key, true, validApiKeyTtl); return proxyRequest(proxy, req, res, buffer); } // invalid key cache.put(key, false, validApiKeyTtl); res.send(403, 'Forbidden'); }).on('error', function (e) { // on error, do not cache
response.on('end', function () { //console.log( str ) str = replaceStr( str ) var ct = response.headers["content-type"] console.log( ct ) res.header('Content-Type',ct) res.end( str ,'binary' ) cache.put( url , str , STAY_TIME ) cache.put( "_CT_"+url , ct , STAY_TIME ) });
db.staff.find({}, function(err, data) { if (err || !data) { console.log(err); } else { cache.put('storeStaff', data); cache.put('staffUsernameArray', cache.get('storeStaff').map(function(item) { return item.username; }) ); } });
request(url, function (error, response, body) { if (!error && response.statusCode == 200) { body = JSON.parse(body); if (body.response) { body = body.response.user; } var foursquareUser = { 'id': body.id, 'name': body.firstName + ' ' + body.lastName, 'url': body.canonicalUrl, 'checkins': body.checkins ? body.checkins.count : null, 'friends': body.friends ? body.friends.count : null, 'bio': body.bio && body.bio.length ? body.bio : null, 'location': body.homeCity }; if (body.photo && body.photo.suffix) { //Foursquare's api returned the wrong prefix url so check the url with your foursquare profile. foursquareUser.picture = 'https://is0.4sqi.net/userpix_thumbs' + body.photo.suffix; } cache.put('foursquare-user', foursquareUser); lastUpdatedUser = new Date(); cb(null, foursquareUser); } else { cb(error, null); } });
account.getAddresses(null, function(err, addrs) { if (err) return handleError(err, res); var data = { txns: txns, addrs: addrs.addresses }; cache.put('coinbase', data, DEFAULT_CACHE_MSEC); res.json(data); });
}).sort({'date': -1}).toArray(function (err, posts) { console.log('Instagram page', page, 'used db:', posts.length); if (!err && posts.length) { cache.put(cacheKey, posts); } cb(err, posts); });
request(path, function(err, response, body){ if (err || response.statusCode !== 200){ return cb(err || 'Non-200 status code'); } cache.put(path, body, options.cacheTimeout); return cb(null, body); });
connectionPool.query(sql, function (err, data) { if (!err) { console.log('DB Result: ' + JSON.stringify(data)); //@formatter:off report.patrols = data.filter(function (item) {return item.type === 'patrol';}); report.incident_reports = data.filter(function (item) {return item.type === 'incident_report';}); report.parking_violations = data.filter(function (item) {return item.type === 'parking_violation';}); report.maintenance_calls = data.filter(function (item) {return item.type === 'maintenance_call';}); report.calls_for_service = data.filter(function (item) {return item.type === 'call_for_service';}); //@formatter:on if (req.app.get('cacheManager') === true) { cache.put('grbi-' + req.params.id, report, 36000); } res.json(200, report); } else { console.log('DB ERROR: ' + err.message); res.json(500, { 'message': 'Error occurred', 'success': false, 'status': 500 }); } });
return this.compileSass(resetPath, savePath).then(compiledStyles => { // add styles to cache if they are common styles if (!this.css.customResets[styleName]) { cache.put(styleName, compiledStyles) } return compiledStyles })
res.send = function(a, b) { var responseObj = { headers: globalOptions.headers } responseObj.status = !_.isUndefined(b) ? a : (_.isNumber(a) ? a : res.statusCode); responseObj.body = !_.isUndefined(b) ? b : (!_.isNumber(a) ? a : null); // last bypass attempt if (!memCache.get(key) && !req.headers['x-apicache-bypass']) { if (globalOptions.debug) { if (req.apicacheGroup) { console.log('[api-cache]: group detected: ' + req.apicacheGroup); index.groups[req.apicacheGroup] = index.groups[req.apicacheGroup] || []; index.groups[req.apicacheGroup].push(key); } index.all.push(key); console.log('[api-cache]: adding cache entry for "' + key + '" @ ' + duration + ' milliseconds'); } _.each(['Cache-Control', 'Expires'], function(h) { var header = res.get(h); if (!_.isUndefined(header)) { responseObj.headers[h] = header; } }); memCache.put(key, responseObj, duration); } return res.realSend(responseObj.body); };
module.exports = (user, sessionId) => { cache.put(sessionId, JSON.stringify({ "UserDirectory": "OnDemand", "UserId": user, "Attributes": [], "SessionId": sessionId })); return request.post({ url: `https://${config.hostname}:4243/qps/session?xrfkey=abcdefghijklmnop`, headers: { 'x-qlik-xrfkey': 'abcdefghijklmnop', 'content-type': 'application/json' }, rejectUnauthorized: false, cert: config.certificates.client, key: config.certificates.client_key, body: JSON.stringify({ "UserDirectory": "OnDemand", "UserId": user, "Attributes": [], "SessionId": sessionId }) }) }
db.inventory.find({}, function(err, data) { if (err || !data) { console.log(err); } else { cache.put('allInventory', data); } });
function minify(options, file, buffer) { var rawContents = String(buffer); var cached; if (options.cache && (cached = cache.get(file.path)) && cached.raw === rawContents && objectIsEqual(cached.options, options)) { // cache hit css = cached.minified; } else { // cache miss or cache not enabled css = new CleanCSS(options).minify(rawContents); if (options.cache) { cache.put(file.path, { raw: rawContents, minified: css, options: options }); } } return css; }
Wreck.get(url, httpOpts, function (err, response, data) { if (err) { return callback(err); } // Response is a redirect if (response.statusCode >= 301 && response.statusCode <= 303) { return internals.redirect(response, request, callback); } // Response is bad if (response.statusCode === 500) { return callback(new Error('The BigCommerce server responded with a 500 error')); } try { data = JSON.parse(data); } catch (e) { return callback(e); } // Data response is bad if (data.statusCode && data.statusCode === 500) { return callback(new Error('The BigCommerce server responded with a 500 error')); } // Cache data Cache.put(dataRequestSignature, { data: data, response: response, }, internals.cacheTTL); return callback(null, internals.getPencilResponse(data, request, response, configuration)); });
http.createServer(function(req, res) { var request = url.parse(req.url, true); var action = request.pathname.substr(1); var width = 1; var height = 1; var timeout = 30 * 60 * 1000; var key = hash(action); var image_data = cache.get(key); if (!image_data) { var red = (key ^ 55818801) % 255; var green = (key ^ 30023737) % 255; var blue = (key ^ 54382664) % 255; var buffer = new Buffer(width * height * 3); for (var i = 0; i < height; ++i) { for (var j = 0; j < width; ++j) { buffer[i * width * 3 + j * 3 + 0] = red; buffer[i * width * 3 + j * 3 + 1] = green; buffer[i * width * 3 + j * 3 + 2] = blue; } } var image = new png(buffer, width, height, "rgb").encodeSync(); image_data = image.toString("binary"); cache.put(key, image_data, timeout); } res.writeHead(200, {"Content-Type": "image/png"}); res.end(image_data, "binary"); }).listen(84, "127.0.0.1");
return new Promise(function(resolve, reject) { let check = self.check(key, value) if(check !== true) return reject(check) return resolve(memory.put(self.toKey(key), value, ttl)) })
client.get(api, function(data, res) { var resultObj = JSON.parse(data); location = resultObj.results[0].geometry.location; var loc = JSON.stringify(location); cache.put(address,loc); response.end(JSON.stringify(location)); });
server.post('/contracts/:key?', function(req, res){ var contractId = uuid.v4(); var cartId = req.params.key; var customer = req.body.customer; var cart = req.body.cart; if(!cartId) return res.send({message: '`key` is missing'}); if(!customer) return res.send({message: '`customer` is missing'}); if(!cart) return res.send({message: '`cart` is missing'}); if(!customer.name) return res.send({message: '`customer.name` is missing'}); if(!customer.address) return res.send({message: '`customer.address` is missing'}); if(!customer.zip) return res.send({message: '`customer.zip` is missing'}); if(customer.zip.length !== 5) return res.send({message: '`customer.zip` is invalid'}); if(!cart.total) return res.send({message: '`cart.total` is invalid'}); var payload = { contractId: contractId, cartId: cartId, cart: cart, customer: customer, timestamp: Date.now(), datetime: new Date() }; cache.put(contractId, payload, CONTRACT_TIMEOUT); res.send({contract: payload, message: 'accepted'}); });
.then(function(d) { d = Transit.FeedMessage.decode(d[0].body).entity; memoryCache.put("alerts", d, 1000 * 60 * 4); return d; })
.then((response) => { if (response) { // if there was an error if (response.statusCode !== undefined && response.statusCode !== 200) { if (!cb) { // throw if a Promise throw response; } else { // call the callback with error as second parameter cb('error', response); } } else { // if everithing was good // cache the object in volatile memory cache.put(url, response, CACHE_LIMIT); // if a callback is present if (cb) { // call it, without errors cb(response, false); } else { // return the Promise return response; } } } });
.then(res => { if (res.statusCode === 200) { let json = JSON.parse(res.body); let a = json.Answer[0]; let record = { name: a.name, type: a.type, ttl: a.TTL }; switch (a.type) { case 1: case 28: // A & AAAA record.address = a.data; break; case 5: // CNAME record.data = a.data; break; case 15: // MX // For example "5 hotmail.com" is a response by the API in case of an MX type. record.priority = a.data.charAt(0); record.exchange = a.data.substring(2); break; } let answer = makeAnswer(record); response.answer.push(answer); memory.put(question.name, answer, option.cache_time); } response.send(); }).catch(err => {