How can I cache an object in Google Apps scripts

前端 未结 1 535
醉话见心
醉话见心 2021-02-06 13:36

I am fetching JSON data from JIRA in a script for a spreadsheet in Google Drive. I have a script that does the fetch just fine, and I am pretty much only fetching the data for

相关标签:
1条回答
  • 2021-02-06 14:19

    Apps Script Cache Service can cache up to 100KB per key, you should not have an issue with only "200" characters. The tighter limitation is only for the key, which is 250 characters.

    The main issue I see with your code is that you're trying to cache the parsed data, instead of the text. Unless your keys are that big (in which case I recommend you used a enconding instead), this should work:

    function _fetchJiraData(targetIssue) {
      var jsonText = cache.get(targetIssue);
      if (jsonText === null) {
        //...prepare your fetch
        var result = UrlFetchApp.fetch(url, options);
        jsonText = result.getContentText();
        cache.put(targetIssue, jsonText);
      }
    
      var data = JSON.parse(jsonText);
      return data;
    }
    
    0 讨论(0)
提交回复
热议问题