Caching using kml and google maps files

I have dynamically generated KML files that I would like to display on Google Maps. This is the easy part, I did it several times earlier, no problem.

I want KML files to be cached by Google for the request. That is, if a person visits a page with a Google Maps attachment in which my KML is loaded and displayed, I want this KML file to be used to load this page. But if the user needs to refresh the page (having the same Google maps URL), I would like the KML file to be reloaded.

The simple โ€œjust add the timestamp argumentโ€ does not work, since I will not control the URLs submitted to Google Maps on the page (only most of the URLs).

Looking at the <Link> and <networkLink> , they seem to allow you to control expiration, caching, updating, etc. on an external resource. Reading the documentation, it would seem that using <refreshMode>onChange<refreshMode> to use a two-layer approach will give me what I want.

After checking this, Google does not actually update the contents of the linked KML file even after 10-20 minutes and reloads several maps (when I provide the same URL in the Maps search field).

These are the KML files that I use:

 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <NetworkLink> <Link> <href>URL</href> <refreshMode>onChange</refreshMode> </Link> </NetworkLink> </Document> </kml> 

...

 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document> <Placemark> <name>NAME</name> <visibility>1</visibility> <Style> STYLE </Style> GEOMETRY </Placemark> </Document> </kml> 

... With URL, NAME, STYLE and GEOMETRY replaced with the correct content. Does anyone have an idea of โ€‹โ€‹what I can do wrong? Or maybe what I want?

+4
source share
2 answers

This is what I know:

  • onChange caches the response completely, if you do not enable the end-to-end proxy version through downloading KML via <viewFormat> , I did not see the update after a few hours.
  • onExpire using the 'max-age' header in the linked KML file does not work on Google Maps (according to the documentation), although I have seen the behavior described in [1] that may be related to the internal expiration time of Google Maps.
  • onExpire using the sort operations <NetworkLinkControl> and <expires> , since the data appears to expire after the expiration date, although the behavior looked closer to [1]
  • onInterval will update the data, assuming that your <viewRefreshTime> is large enough, and will do it according to its own schedule (unreliability time in the slightest degree), but the map view starts to decrease completely (it doesnโ€™t seem to be, this is a way to fix it).

[1] If you specify 'max-age' X seconds and you leave the page open, KML will never refresh while the page is focused. If you move the focus to another web page or application, wait a while after refreshing the page (sometimes itโ€™s enough to wait 2 minutes, sometimes itโ€™s not), and you return to the page, it can take up to 30 requests in quick succession to try to refresh data if you do not return the content, or once if you return the content.

In short: managing the cache of KML files inside Google Maps using onExpire and onInterval not reliable. At some point after downloading the data, it will be updated, as the Google cache got rid of it. But when does this cache expire? Some random time, which is at least 5 minutes.

+1
source

To expire, Google follows the expiration of the headers, but it expires for a minimum of 5 minutes to prevent third-party servers with effective denial of service hits.

+1
source

All Articles