Last active
September 1, 2015 03:59
-
-
Save ernestlv/31d211e349187c408a76 to your computer and use it in GitHub Desktop.
Node.js to retrieve data from a cache object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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