使用缓存服务来最大程度地减少使用 GAS 提交大型表单期间的属性存储数据调用

问题描述 投票:0回答:1

我需要将 Google 表单数据发送到外部 api,该 api 使用 api-key 来验证发出的每个请求。因此,我收集了 api-key 并将其保存在属性商店中。

由于必须避免多次调用属性存储,因此当有大量传入表单提交时,我认为使用缓存服务是谷歌的选择。在阅读官方文档时,我不确定我是否理解得很好。

我有以下代码,在调用时提供 api-key。我需要在其中引入缓存服务。非常感谢任何指点。

function getApiKey() {
    var apiKey = PropertiesService.getUserProperties().getProperty("API_KEY")
    if (apiKey) 
      return apiKey;
    else
      return "INVALID";
}
google-apps-script
1个回答
1
投票

相当于

PropertiesService.getUserProperties().getProperty("API_KEY")
CacheService:

CacheService.getUserCache().get("API_KEY")

© www.soinside.com 2019 - 2024. All rights reserved.