mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

OfflineTilePyramidRegionDefinition caching style url

Open Jmaguerre opened this issue 9 years ago • 3 comments

Platform: Android Mapbox SDK version: 4.2.0-beta.5@aar

So what's happening is that I have hosted style definitions in my server and creating offline regions for them seem to be caching the content of the http request and therefore always downloading the same tiles for those urls.

Steps to trigger behavior

  1. Create an offline region definition with a custom url
  2. Download region
  3. Create a new offline region definition with the same url but the contents of the style definition hosted in that url are different from the first created.
  4. Download region.

Expected behavior

New tiles defined by the url are downloaded.

Actual behavior

It seems to have the contents of the url cached so it does not download tiles defined in the new style.

I am aware that caching is a good practice but I think in this case it should not cache the contents of the style urls.

I am also thinking what would happen if styles hosted for mapbox urls (mapbox://styles/mapbox/streets-v9, etc.) change, I think the same problem will occur.

I hope I've explained myself, if not please let me know. Thanks.

Jmaguerre avatar Feb 08 '17 13:02 Jmaguerre

This is the intended behavior of offline regions (and of URLs in general). If you have different resources, they must have different URLs.

Updates to Mapbox styles (and in general, updates to any resource) are handled through use of the standard HTTP headers for caching, Expires, Cache-Control, and Etag. The offline implementation will refresh resources according to the schedule established by these headers.

jfirebaugh avatar Feb 08 '17 17:02 jfirebaugh

Hi @jfirebaugh thanks for the reply, I took a look into the mbgl-offline.db database and I don't understand why for the resource with the same url it doesn't update its etag column when the etag of the http response is different. Isn't this supposed to happen when it changes and you request the same url?

Jmaguerre avatar Feb 08 '17 18:02 Jmaguerre

It does update the etag: https://github.com/mapbox/mapbox-gl-native/blob/62ea1f21858c69f6921c775ba7a3de201f0514d8/platform/default/mbgl/storage/offline_database.cpp#L290-L290

jfirebaugh avatar Feb 08 '17 18:02 jfirebaugh