chernevik
chernevik

Reputation: 4000

Caching in UrlFetchApp

In Google App Script I'm using UrlFetchApp() to bring in some code served from an outside host. I make changes to the code served on that host but these aren't appearing in the code run by script.

My server logs show that the desired is sometimes requested (and served) but it isn't showing up in the script.

I'm using optAdvancedArgs in my UrlFetchApp call, passing in {"headers" : {"Cache-Control": "no-cache"}

but this isn't helping.

Is there some kind of caching of resources obtained by UrlFetchApp(), and if so how can I turn it off?

Upvotes: 2

Views: 1996

Answers (2)

Kleberson Leite
Kleberson Leite

Reputation: 29

Set your URL dynamicaly like this:

var url = "https://yoururl.com/?" + Math.floor(Math.random() * 1000000000);
var responseUrl = UrlFetchApp.fetch(url).getContentText();

Upvotes: 0

chernevik
chernevik

Reputation: 4000

Setting the header Cache-Control to max-age=1 seemed to fix the problem.

This discussion provided some helpful context: https://developers.google.com/speed/docs/best-practices/caching

Upvotes: 2

Related Questions