Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Last active September 1, 2015 03:59
Show Gist options
  • Save ernestlv/31d211e349187c408a76 to your computer and use it in GitHub Desktop.
Save ernestlv/31d211e349187c408a76 to your computer and use it in GitHub Desktop.
Node.js to retrieve data from a cache object
var cache = require("./cache");
function doRequest(url, httpRes){
var data = cache.get(url);
if (data){
httpRes.json(200, JSON.parse(data));
}
return !!data;
}
exports = module.exports = {
getClients: function(httpRes){ //web service request
var url = "clients";
return doRequest(url, httpRes);
},
getSales: function(httpRes){ //web service request
var url = "sales?client="+req.client;
return doRequest(url, httpRes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment