here's how to use google cache to persist data for a while .. if you run x, then run it again immediately, you'll see it runs at 10 times the speed. So the cache persists across function calls.
// we need to get data for a specific sheet/workbook combination
//could be in google cache or nowhere
function t() {
Logger.log( getPersist ("0At2ExLh4POiZdFAzUElyTGNQLW90aEFKeHhJZDR1WWc","freegeoip"));
}
function getPersist ( wb, ws) {
var googCache = CacheService.getPublicCache();
var sheetString = googCache.get(wb + "!" + ws ) ;
if (sheetString)
// we know it
return JSON.parse (sheetString);
else {
// we know nothing, open the workbook & cache
sw = SpreadsheetApp.openById(wb).getSheetByName(ws).getDataRange().getValues();
googCache.put(wb + "!" + ws, JSON.stringify(sw), 60);
return sw;
}
}
function x () {
mcpher.useTimer('a').start('first');
getPersist ("0At2ExLh4POiZdFAzUElyTGNQLW90aEFKeHhJZDR1WWc","freegeoip");
mcpher.useTimer('a').stop();
Logger.log(mcpher.useTimer().report());
}