google-apps-script - 谷歌应用脚本 CacheService 奇怪的行为
问题描述
我使用应用程序脚本为谷歌驱动器做了一个简单的添加。它计算点击文件的次数。代码片段:
let onHomepage = (e) => {
return createHomeCard();
};
let createHomeCard = (text = "") => {
var contextText = CardService.newTextParagraph()
.setText("<b>Click on a file to start</b>");
var tapsText = CardService.newTextParagraph()
.setText(text);
// Assemble the widgets and return the card.
var section = CardService.newCardSection()
.addWidget(contextText)
.addWidget(tapsText);
var card = CardService.newCardBuilder()
.addSection(section);
return card.build();
};
let onDriveItemsSelected = (e) => {
updateCount();
return createHomeCard("count : " + getCount());
};
let updateCount = () => {
let count = parseInt(CacheService.getUserCache().get("count"));
if (!count){
count = 0;
}
count += 1;
CacheService.getUserCache().put("count", count + "");
};
let getCount = () => {
return CacheService.getUserCache().get("count");
};
每次点击都是一个简单的计数+=1。
但是,如果我的驱动器只有 3 个文件,我不能让它通过 3,正如您在下面附加的视频中看到的那样,如果我点击第一个文件,计数将回到 1。
我错过了什么?
在这个片段中,我使用“CacheService”来存储和检索缓存,但我也尝试过“PropertiesService”并且都给了我相同的结果。
请指教。
谢谢。
解决方案
推荐阅读
- memory - WGAN-GP 的 Pytorch Autograd 中的内存泄漏
- odoo - 有谁知道为什么量化和产品移动会不匹配?
- python-3.x - 我想检查一个元素是否存在于嵌套列表中并返回它的索引
- javascript - 替换/操作 url 中的“主机名”而不重定向到它
- html - 如何在引导程序 4 折叠按钮中更改按钮文本
- python-3.x - TKInter 字体的多种变体
- google-earth-engine - 谷歌地球引擎中每个像素的递归函数
- python - Python XML to CSV 帮助新手
- gcc - 在 arm-none-eabi-gcc 中找不到 nano.specs
- r - 将样本大小添加到 ggplot boxplot