【发布时间】:2019-03-14 17:32:30
【问题描述】:
我在从 Google Apps 脚本的用户缓存中检索对象时遇到问题。我没有得到 null,我只是得到一个空对象。我什至想知道该对象是否已正确保存到用户缓存中。非常感谢任何帮助。这是我到目前为止所拥有的......
此代码不起作用:
// global variable to access user cache
var cache = CacheService.getUserCache();
// the function to save to cache for an end-user
function saveToUserCache(dynamicObj) {
Logger.log(dynamicObj); // the object displays here
cache.putAll(dynamicObj, 300);
Logger.log(cache.getAll(['test1', 'test2'])); // the object does not display here
}
这是从 .html 文件中调用的:
...
// Object being passed dynamically:
var testObj = {'test1': "value1",'test2': "value2"};
google.script.run.withSuccessHandler(onSuccess).saveToUserCache(testObj);
...
此代码有效:
// global variable to access user cache
var cache = CacheService.getUserCache();
// object to pass into the function
var testObj = {'test1': "value1",'test2': "value2"};
// the function to save to cache for an end-user
function saveToUserCache() {
Logger.log(testObj); // the object displays here
cache.putAll(testObj, 300);
Logger.log(cache.getAll(['test1', 'test2'])); // the object displays here
}
给出一些上下文...我需要使用第一段代码的原因是因为我使用withSuccessHandler() 从前端GUI 传递一个对象。如您所见,该对象在第一个 Logger 中显示良好,因此数据到达saveToUserCache() 函数,但在那之后,我无法从第一块代码的缓存中检索它。我做错了什么?
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: caching google-apps-script web-applications