Created
June 10, 2011 12:18
-
-
Save feedhenry-gists/1018731 to your computer and use it in GitHub Desktop.
Mash Hash Cache Hashing
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
// Call the server side function to get the mashup data | |
$fh.act({ | |
act: 'getMashup', | |
req: { | |
hash: hash, | |
timestamp: new Date().getTime() | |
} | |
}, function (res) { | |
var mashup = res; | |
// Check if our hash's match, so we can use the locally cached data | |
if (hash === mashup.hash) { | |
// we already have the latest data, lets use our cachedData | |
updateMashup(hash, cachedMashup); | |
} | |
else { | |
// Hash's don't match, so server has included the newest data to use | |
// Lets save it, along with the new hash value | |
$fh.data({ | |
act: 'save', | |
key: 'mashup_data', | |
val: JSON.stringify(mashup) | |
}, function (res) { | |
// mashup data saved, no need to do anything else | |
}, function (error) { | |
alert(error); | |
}); | |
// No need to wait for asynchronous saving above to finish. Lets go ahead | |
// and show the latest mashup data | |
updateMashup(hash, mashup); | |
} | |
}, function (code,errorprops,params) { | |
// Something went wrong with server side function call, let's alert the user | |
alert('Failed to get mashup from server. Error:' + code); | |
enableMashupButton(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment