I'm building some functionality in the onEdit(e)
function of my google sheet.
However, I noticed that the 'reaction time' of my script became slower as more and more sheets were added in the spreadsheet. It reached the point where the user-experience became very poor.
The line of code that is causing the increasing delay is the standard function
getSheetByName(name)
Google does provide a standard getSheetByID(
) function, so I made one myself, however it had the same performance as the getSheetByName(name)
function.
For that reason, I wanted to put this Sheet object in cache, in order to retrieve it faster during my onEdit(e)
function:
function GetTemplateSheet(){
let cache = CacheService.getScriptCache();
let templateSheet = JSON.parse(cache.get("templateSheet"));
if (!templateSheet){
let spreadSheet = SpreadsheetApp.getActiveSpreadsheet();
templateSheet = spreadSheet.getSheetByName('myTemplate');
cache.put("templateSheet", JSON.stringify(templateSheet));
}
return templateSheet;
}
However this does not seem to work. I'm not getting back the object that I put in. I just cannot figure out how to overcome this.