Data.xml cache problem

4 views
Skip to first unread message

andrewpa...@hotmail.com

unread,
Jul 24, 2008, 10:48:40 AM7/24/08
to KML Developer Support - Getting Started with KML
My set-up;

index.asp Displays a blank map, and a form for collecting new location
data.
This new data is passed to tracking.asp which updates the database,
writes out a new data.xml file (overwriting the previous server copy),
then redirects to results.html which displays all the results by
reading the xml file using line 9 of this template code

function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(51.87543367554868,
-0.7657934725284576), 4);
map.removeMapType(G_HYBRID_MAP);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setMapType(G_MAP_TYPE);
GDownloadUrl("data.xml", function(data) {
var xml = GXml.parse(data);
var markers =
xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var latlng = new
GLatLng(parseFloat(markers[i].getAttribute("lat")),

parseFloat(markers[i].getAttribute("lng")));
var mtitle = markers[i].getAttribute("title");
opts=
{

"title": mtitle
}
map.addOverlay(new GMarker(latlng, opts));
}
});
}
}

I think data.xml is being cached as I do not always see the results in
IE. If you you submit a new entry and result.html is not showing that
entry, then put data.xml in the URL to view it in the browser, the
latest result isn't at the end of the list. Push Ctrl-F5 (refresh),
and it shows up at the end, and going back to result.html will then
show it on the map.

How do I create an auto Ctrl-F5 on data.xml whenever results.html is
loaded or refreshed?

http://www/paulscorner.info/index.asp if you want to look at the code
online (NB it will always work first time ~ try entering a new
location again and it probably will not show the 2nd one)

Regards Paul

andrewpa...@hotmail.com

unread,
Jul 30, 2008, 9:22:58 AM7/30/08
to KML Developer Support - Getting Started with KML
Can anyone even guess at a solution?

barryhunter [KML Guru]

unread,
Jul 30, 2008, 1:41:30 PM7/30/08
to KML Developer Support - Getting Started with KML
I think maybe you in the wrong group, see
http://groups.google.com/group/Google-Maps-API/

but yes GDownloadUrl uses the browser to fetch the file, and so it
undertakes to cache it like it does any other file. IE in particular
is known to be quite arbitrary and aggressive, if the server doesn't
supply any sort of hints.

Two main ways to solve this:

1) get your server to issue appropriate caching headers for data.xml
(eg Expires - or no-cache)

2) defeat the cache by changing the url of the file each time, and do
this in such a way that your server will return the same file, but the
browser sees a new url so it fetches it fresh, eg,

GDownloadUrl("data.xml?nocache="+(new Date()).getTime(),
function(d.....

which appends the current time on the end of the url, but most
webservers will ignore the query string (after the ?) and return the
same xml
(I cant get to your server to see if it does)
Reply all
Reply to author
Forward
0 new messages