Google Apps脚本UrlFetchApp.fetch返回缓存副本 [英] Google Apps-script UrlFetchApp.fetch returning cached copy
问题描述
我在谷歌应用程序脚本中使用UrlFetchApp来执行get操作,如下所示:
var optAdvancedArgs = {
method:GET,
headers:{Cache-Control:no-cache,Pragma:no-cache},
};
var response = UrlFetchApp.fetch(url,optAdvancedArgs);
尽管我尝试在头文件中禁用缓存,但我得到的响应始终是缓存副本。如果我使用相同的URL在我的控制台中执行wget,我会看到收到最新版本。
我的问题是:我怎样 em>在执行UrlFetchApp.fetch时禁用缓存?我的代码有什么问题吗?
我可以通过使用max-age = 0来解决这个问题。我的缓存控制头,例如:
var url =http://www.stackoverflow.com;
var options =
{
//确保我们每次都得到新的站点副本。
headers:{'Cache-Control':'max-age = 0'}
};
var response = UrlFetchApp.fetch(url,options)
听起来像Google App Engine有一个类似的问题。有人开了一个问题,但它似乎已关闭。
I am using UrlFetchApp in a google apps script to perform a get, as follows:
var optAdvancedArgs = {
"method": "GET",
"headers": {"Cache-Control": "no-cache", "Pragma": "no-cache"},
};
var response = UrlFetchApp.fetch(url, optAdvancedArgs);
Despite my attempt to disable the cache in the headers, the response I get is always a cached copy. If I perform a wget in my console using the same url, I see receive an up to date version.
My question is: How can I really disable the cache when performing a UrlFetchApp.fetch? Is there something wrong with my code?
I was able to overcome this issue by using "max-age=0" in my Cache-Control header, e.g.:
var url = "http://www.stackoverflow.com";
var options =
{
// Ensure we get a fresh copy of the site every time.
headers : {'Cache-Control' : 'max-age=0'}
};
var response = UrlFetchApp.fetch(url, options)
It sounds like Google App Engine has a similar problem. Someone opened an issue however it appears to have been closed.
这篇关于Google Apps脚本UrlFetchApp.fetch返回缓存副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!