maplibre / maplibre-native

MapLibre Native - Interactive vector tile maps for iOS, Android and other platforms.
https://maplibre.org
BSD 2-Clause "Simplified" License
1.09k stars 322 forks source link

Source.setMinimumTileUpdateInterval() is not working #2004

Open michalgwo opened 10 months ago

michalgwo commented 10 months ago

Describe the bug As MapTiler doesn't provide the Cache-Control HTTP response header for every tileset, I wanted to override it in the code in my Android app. What seems to be made for that is Source.setMinimumTileUpdateInterval(), but it doesn't seem to work. After setting this value to 14400000, the MapLibre still makes duplicate network requests every time I pan/zoom the map.

To Reproduce Steps to reproduce the behavior:

  1. Set up MapLibre on Android (I didn't test on iOS) with any style source that doesn't have a Cache-Control HTTP response header, for example, this style has a source like that: https://api.maptiler.com/maps/openstreetmap/style.json?key={api_key} (I don't know if it was on purpose or not, but I wrote to them about that, so they may update it in the future), you can get the free API key on maptiler.com
  2. Change minimumTileUpdateInterval after the style is loaded:
    style.getSourceAs<VectorSource>("openmaptiles")?.apply {
    minimumTileUpdateInterval = 14400000
    } 
  3. Pan around, zoom in, zoom out (to capture the same tiles multiple times), and check logs. Look for: [HTTP] Request was successful (code = 200). [HTTP] This request was cancelled (request url) It keeps requesting the same tiles every time you view this tile, so it seems like minimumTileUpdateInterval is 0.

Expected behavior After setting minimumTileUpdateInterval to 14400000, MapLibre should keep tiles in the cache for 14400000 milliseconds and not make any more requests for the same tiles until this time passes

Platform information (please complete the following information):

louwers commented 10 months ago

https://github.com/maplibre/maplibre-native/blob/8c940cb7a65ad4c865cc51d1b8ce88dd425c52b8/platform/default/src/mbgl/storage/online_file_source.cpp#L478-L485

It looks like a Cache-Control HTTP header is needed to use this functionality. Otherwise it always uses a timeout of zero regardless of the set minimum tile update interval.

michalgwo commented 10 months ago

https://github.com/maplibre/maplibre-native/blob/8c940cb7a65ad4c865cc51d1b8ce88dd425c52b8/platform/default/src/mbgl/storage/online_file_source.cpp#L478-L485

It looks like a Cache-Control HTTP header is needed to use this functionality. Otherwise it always uses a timeout of zero regardless of the set minimum tile update interval.

Is it supposed to be like that? Seems like this function is made to bypass configuration set by tileserver, but it doesn't in this case.

louwers commented 10 months ago

Yes, I think so. From the changelog:

Introduced Source.minimumTileUpdateInterval to override the expiration time set via HTTP headers with a longer expiration time on the client.

They keyword here is 'override'. There is nothing to override if no expiration time is present in the HTTP headers.