Is there something built into PropertiesService that is supposed to detect when strings get to large?

48 Views Asked by At

I've had this code running for a long time and today it started failing. As I was looking at the malformed html I realized that I was seeing something from an object that I had also stored in Script PropertiesService and then I saw that function savegobjScriptProperties and realized that the object that I had created with another script was spilling over into other slots. Is there something in Script Properties I've missed so that I can avoid this issue?

function getgobjHtml() {
  let obj = gobj.globals;
  let gn = 0;
  let sn = 0;
  let html = '';
  html += '<table><tr><th>Property</th><th>Value</th></tr>';
  html += '<tr><th>gobj.globals</th><th>From Globals</th></tr>'
  for (let p in obj) {
    html += Utilities.formatString('<tr><td><textarea id="gp%s">%s</textarea></td><td><textarea id="gv%s">%s</textarea></td></tr>', gn, p, gn++, obj[p]);
  }
  html += Utilities.formatString('<tr><td><textarea id="gp%s"></textarea></td><td><textarea id="gv%s"></textarea></td></tr>', gn, gn++);
  html += '</table>';
  html += Utilities.formatString('<br /><input type="button" value="Save Global Properties" onClick="savegobjGlobalProperties(%s);" />',gn);
  html += '<div id="gmsg"></div>';
  html += '<table><tr><th>Property</th><th>Value</th></tr>';
  html += '<tr><th>gobj.init</th><th>From Script Properties</th></tr>'
  obj = gobj.init;
  for (let p in obj) {
    html += Utilities.formatString('<tr><td><textarea id="sp%s">%s</textarea></td><td><textarea id="sv%s">%s</textarea></td></tr>', sn, p, sn++, obj[p]);
  }
  html += Utilities.formatString('<tr><td><textarea id="sp%s"></textarea></td><td><textarea id="sv%s"></textarea></td></tr>', sn, sn++);
  html += '</table>';
  html += Utilities.formatString('<br /><input type="button" value="Save Script Properties" onClick="savegobjScriptProperties(%s);" />',sn);
  html += '<div id="smsg"></div>';
  html += '<br /><br /><input type="button" value="Close" onClick="google.script.host.close();" />';
  return HtmlService.createHtmlOutput(html).getContent();
}

By the way the length of the stringified object was 390,113 characters so there's not enough room for my object in either place. So I guess I'll have to go with another approach.

I guess I should have checked this early but according to this link the max value size for a Properties Service Value is on 9KB. So much for barreling ahead without thinking. Google Quotas put the Properties key limit at 9KB and the total at 500KB. According to this link The maximum length of a cache key is 250 characters. The maximum amount of data that can be stored per cache key is 100KB. The same link puts the maximum expiration in seconds at 21600 (6 hours) but they add the caveat "The specified expiration time is only a suggestion; cached data may be removed before this time if a lot of data is cached." I did find that if you try to put to much into a cache key you do get a warning that your argument is to large. Unfortunately the Properties Service doesn't complain at all. They just let you think every thing is ok even though it's not.

1

There are 1 best solutions below

0
Cooper On

The answer to my question is NO. There nothing that tells you that you are trying to put too much into a key. The cache service does have that capability.