Caching in Google Gadgets
November 22, 2008
Javascript | Web Building | XML

When creating a Google gadget that pulls data from an XML file, you will probably notice that the data doesn't update right away in the gadget even after you have changed the file. This caching behavior can make it very difficult to troubleshoot, and you'll probably want to shut it off while developing.
It took me a while to find this so I'm posting it here:

From Google's "Refreshing the Cache" instructions:


To make sure your gadget fetches fresh new content at least once per interval, simply specify a value (measured in seconds) for the refreshInterval parameter. For example:
// Fetch fresh content every half hour
_IG_FetchContent("http://news.google.com/?output=rss", callback, { refreshInterval: (60 * 30) });

// Fetch fresh content every 10 minutes
_IG_FetchContent("http://news.google.com/?output=rss", callback, { refreshInterval: (60 * 10) });

// Fetch fresh content every 30 seconds
_IG_FetchContent("http://news.google.com/?output=rss", callback, { refreshInterval: 30 });

// Disable caching completely and fetch fresh content every time -- !! Try to avoid using this !!
_IG_FetchContent("http://news.google.com/?output=rss", callback, { refreshInterval: 0 });

function callback(response) { ... }



Ads by Google

Posted by ellen at November 22, 2008 07:45 PM

If you notice that your Gadget's code is also being cached, check in your sandbox that the gadget in question does not have the "Cached" checkbox checked.

Picture 28.jpeg


So for example, since I am constantly tinkering with my Daily Bailout widget, I use the following code for fetching the XML data:

function displayBailouts(val) 
			{
			  var url = "http://thedesignspace.net/widgets/bailout-data4.xml";
			  
			  _IG_FetchXmlContent(url, function (response) {
					   refreshInterval: (0);
					    if (response == null || typeof(response) != "object" || response.firstChild == null) {
					      _gel("content_div").innerHTML = "invalid response "+typeof(response);
							    return;
							}//end if 



Ads by Google


Ads by Google

 RSS   |   Contact Me


Ads by Google