什么是getPublicCache()这些天?



我发现了一个创建RSS提要的GAS脚本,我试图学习这种语言,以便我可以修改它。在脚本CacheService.getPublicCache()中使用了一种方法,但我找不到任何关于它的文档,而不是它可以用于一些文章/问题(SO, GSuite Dev log和ctrlq.org),其中大多数使用相同的场景生成RSS提要并返回它,如果它已经生成。(代码示例来自Ctrlq.org)

function getRssFeed() {
var cache = CacheService.getPublicCache();
var cached = cache.get("rss-feed-contents");
if (cached != null) {
return cached;
}
var result = UrlFetchApp.fetch("http://example.com/my-slow-rss-feed.xml"); //takes 20 seconds to get
var contents = result.getContentText();
cache.put("rss-feed-contents", contents, 1500); // cache for 25 minutes
return contents;
}

当前缓存服务(getDocumentCache, getScriptCache, getUserCache)的文档使用相同的生成和提供RSS提要示例来使用缓存服务,特别是使用getScriptCache。(来自当前GAS文档的代码示例)

function getRssFeed() {
var cache = CacheService.getScriptCache();
var cached = cache.get("rss-feed-contents");
if (cached != null) {
return cached;
}
var result = UrlFetchApp.fetch("http://example.com/my-slow-rss-feed.xml"); // takes 20 seconds
var contents = result.getContentText();
cache.put("rss-feed-contents", contents, 1500); // cache for 25 minutes
return contents;
}

由于我无法找到关于getPublicCache是什么的文档,这些天getPublicCache是哪种方法?我假设它是getScriptCache作为当前文档示例在相同的上下文中使用它作为其他文章使用getPublicCache的例子。

感谢rubn的评论,Google Apps Script发布页面有了答案——从2014年9月4日的发布开始,最后一个要点。

分别用getUserCache()getScriptCache()getUserLock()getScriptLock()代替CacheService方法getPrivateCache()getPublicCache()LockService方法getPrivateLock()getPublicLock()。旧的方法名称已被弃用,但将继续发挥作用。新名称遵循与PropertiesService相同的约定。

按照上述顺序,getPublicCache()现在是getScriptCache()

最新更新