Created
June 10, 2011 12:19
-
-
Save feedhenry-gists/1018733 to your computer and use it in GitHub Desktop.
Mash Hash Cache Hashing getMashUp
This file contains 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
function getMashup() { | |
var response = {}; | |
// Check the cloud cache to see if we have data | |
var cached = readCache(); | |
// No cahced data in cloud | |
if( ""=== cached ) { | |
// Get data from remote web services | |
var data = doMashUp(); | |
// Create MD5 hash of data | |
var hash = createHash($fh.stringify(data)); | |
// Store data and hash in cloud cache | |
doCache(hash, data); | |
// Build response object | |
response = {'data': data, 'hash':hash, 'cached':false}; | |
} | |
else { | |
//transform cached data from string type to object type | |
cached=$fh.parse(cached); | |
// Check if client hash value present & correct | |
if( $params.hash && $params.hash === cached.hash ) { | |
// Don't need to send data back to client as hash is up to date | |
response = {'hash':$params.hash, 'cached':true}; | |
} | |
else { | |
// Hash value from client missing or incorrect, return cached cloud data | |
response = cached; | |
} | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment