Skip to content

Instantly share code, notes, and snippets.

@nsisodiya
Created February 2, 2012 09:27
Show Gist options
  • Save nsisodiya/1722542 to your computer and use it in GitHub Desktop.
Save nsisodiya/1722542 to your computer and use it in GitHub Desktop.
Caching Response for API Calls
getCountries: function(){
var self = this;
function onSuccessCB(DataObj) {
$.jCacher.add("getCountries", DataObj);
clk.util.com.hideProcessing();
var SettingsResponse = DataObj.getData();
if (SettingsResponse.error != null) {
clk.util.com.showErrorMessage("Unable to get Contact Info" + SettingsResponse.error);
}else{
self.CountriesList = SettingsResponse.response;
}
};
function onFailureCB(dataObj) {
$.jCacher.add("getCountries", DataObj);
clk.util.com.hideProcessing();
clk.util.com.showErrorMessage(clk.locales.error.en.UpdateError);
};
var theValue = $.jCacher.get("getCountries");
if(theValue){
onSuccessCB(theValue.value);
}else{
clk.util.com.showProcessing();
this.svc.getCountries(onSuccessCB,onFailureCB);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment