3

I am using Leaflet and infostream's fork of mbtiles-php to serve MBTiles stored on my server. I'm using a Leaflet layer group (and a layer control) to serve two MBTiles files. When I toggle between the two layers using the layer control at the same zoom level, my local cache is rebuilt rather than reusing the existing tiles.

In the Leaflet layer group example, toggling between the two layers reuses the locally cached tiles, although I assume that the example tileset is not in MBTiles format. In the examples that I've seen through MapBox (using MBTiles but with the ModestMaps library), the locally cached tiles are also being reused.

My information on reuse of caching come from clearing the cache (using Chrome) and then examining the developer tools network tab to see the tiles being built (or not built).

Am I missing some customization of mbtiles-php that would allow reuse of tiles? I've seen reference to mbutils, but I'd prefer to keep the tiles in MBTiles format.

1

I was able to fix this in mbtiles-php tileserver.php by adding this call:

header('Cache-Control: max-age=3600');

when serving out the image tiles. I have no idea of the wisdom of this, although I did notice that in both the Leaflet and Mapbox examples that I point to above, they have similar 'Cache-Control' HTTP headers on the PNG tiles they serve. Here is the relevant diff:

244a245
>         header('Cache-Control: max-age=3600');
259a261
>         header('Cache-Control: max-age=3600');

Please let me know if this is a bad idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.