Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Apps-script UrlFetchApp.fetch returning cached copy

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?

like image 523
MM. Avatar asked Dec 27 '22 14:12

MM.


1 Answers

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.

like image 55
Daniel Avatar answered Apr 02 '23 18:04

Daniel