mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Changing the published map, while caching tiles, doesn't update the style

Open Alexphauge opened this issue 9 years ago • 9 comments

So a thing I just noticed, our design guy was complaining about how the style in our application didn't update when he published something new from the Mapbox studio. I took a look at it, and it seems he just needed to clear the caches.

One of the reasons we chose Mapbox was this feature though, to dynamically, on the fly, change the style for all our users without them having to download an update. Would it be possible to see if the MapID has received an update/been published and then clear the cache on devices/in the editor?

Alexphauge avatar Aug 21 '17 12:08 Alexphauge

I took a look at it, and it seems he just needed to clear the caches.

Correct, there's an option in the Mapbox menu.

Other than that the cache is a simple FIFO (first in, first out) implementation. Meaning only once the cache limit has been exceeded tiles are "refreshed".

Would it be possible to see if the MapID has received an update/been published and then clear the cache on devices/in the editor?

While the style API does have created and modified properties there are two bigger challenges standing in the way of an implementation :

  1. We currently do not evaluate or even request style metadata before requesting tiles themselves. This would need major changes to how tiles are requested - but would make sense to have anyway.
  2. We probably would have to change the database structure of the cache to store that additional data (at least the date) and adjust the pruning logic as well.

Currently these changes are low priority, but your point makes sense and we will re-evaluate.

wilhelmberg avatar Aug 21 '17 16:08 wilhelmberg

@Alexphauge for the time being an easy workaround might be to poll the style object when your app starts and then call MapboxAccess.ClearCache() if needed.

https://github.com/mapbox/mapbox-unity-sdk/blob/86282c925c823941498939c2ed14151a662be31f/sdkproject/Assets/Mapbox/Unity/MapboxAccess.cs#L70-L77

wilhelmberg avatar Aug 21 '17 17:08 wilhelmberg

@Alexphauge Also, you can manually clear the cache in the editor through the Mapbox menu item. On devices, you can clear the cache by deleting the application.

As @BergWerkGIS mentioned, I recommend that you query your style's modified date and use that to see if you should clear the cache at runtime. We're doing something very similar to this for the style optimized vector tiles. See StyleSearchWindow.cs.

david-rhodes avatar Aug 21 '17 18:08 david-rhodes

Thanks, we'll probably look into that workaround in our next sprint. 👍

Alexphauge avatar Aug 22 '17 08:08 Alexphauge

Oh thank god. I was trying to figure this problem all day, thanks for the post. I'm using Unity and the changes I made through our mapbox account were not being reflected in the Unity scene. For anyone with the same problem just click on Mapbox->Clear Caches

cobaltplay avatar Jan 02 '18 20:01 cobaltplay

@BergWerkGIS Hi, I am new to Mapbox and I am having the same issue. I would like for Mapbox to clear caches on IOS and Android devices each time the "Scene" is opened. I see what you mentioned before and I am very interested in how to apply this for my unity scene, so when I build for any device, it automatically clears the cache every time I get in the maps "scene". Thanks and sorry but I am new at coding.

sebsonic87 avatar Feb 26 '18 01:02 sebsonic87

@sebsonic87 statements from above still hold true.

Easiest would be to just call MapboxAccess.ClearCache() every time your scene opens. But that comes with the disadvantage that you will throw away tiles that haven't changed leading to slower startup and longer time to display the map. Especially after your style has stabilized and updates are not that frequent anymore.

Same could be achieved more easily by going into Mapbox -> Setup -> Configuration and setting the MBTiles Cache to 0. This would cache tiles in memory when you app is running but not persist them to disk.

Advanced and preferred solution would be to query the style object, look at the created/modified dates, save them and on next scene open compare them and only if the modified property of the style is newer than the date you saved call MapboxAccess.ClearCache().

wilhelmberg avatar Feb 26 '18 09:02 wilhelmberg

append ?fresh=true to the end of your style url

zeluspudding avatar May 28 '19 21:05 zeluspudding

there's an option in the Mapbox menu.

you can manually clear the cache in the editor through the Mapbox menu item

@wilhelmberg, @david-rhodes Sorry, where is that menu item? I think I searched everything...

greatvovan avatar Feb 03 '23 17:02 greatvovan