Open westnordost opened 7 months ago
Your use case seems to fall somewhere in between an offline database and a cache. The maximum age of a cached tile is set by the max age HTTP header. It should not be set manually.
What I suggest you do is set the date of the offline region as part of the metadata when downloading it. You can periodically run listOfflineRegions
and deleteOfflineRegion
when the metadata indicates it is older than 2 weeks old.
The maximum age of a cached tile is set by the max age HTTP header. It should not be set manually.
That's a property which is controlled by the map vector tile service provider. I.e. as the developer of the client, not owning the server, I cannot change whatever max age they set.
What I suggest you do is set the date of the offline region as part of the metadata when downloading it. You can periodically run listOfflineRegions and deleteOfflineRegion when the metadata indicates it is older than 2 weeks old.
That's what I wrote under Describe alternatives you've considered. The problem is that I need to trigger that from the UI thread, but for workers, there is no ui thread.
That's what I wrote under Describe alternatives you've considered. The problem is that I need to trigger that from the UI thread, but for workers, there is no ui thread.
Maybe it's possible to lift that limitation.
That would solve the use case. (But a setting like that would certainly be more convenient and useful for any library user that stores offline region in a managed manner)
Is your feature request related to a problem? Please describe.
In StreetComplete, when an area is downloaded for offline (editing), the vector map is also downloaded for that area. Both the OSM map data and the vector map data is guaranteed to be kept in cache for two weeks. After two weeks, downloaded regions are cleared (in a background worker).
The OfflineManager already offers settings to evict old cached tiles based on when a total certain size is exceeded and based on when a total certain count is exceeded. It does currently not offer a setting to evict old tiles based on age.
We need to be able to evict cached tiles based on age, rather than count or size, because we want to guarantee to the user that the downloaded data is good for two weeks. It would be quite annoying for the user if he downloaded the data (e.g. for an upcoming vacation) but due to him using the app too much in the meantime (= new tiles are downloaded elsewhere), his previously downloaded data is not available anymore when he needs it.
Describe the solution you'd like
A setting for the OfflineManager, e.g.
OfflineManager::setMaximumAmbientCacheAge
Describe alternatives you've considered
It is theoretically possible to implement this behavior oneself, by attaching metadata that contain the download date to the downloaded offline regions and then iterating through all downloaded regions in a worker thread and evicting all that are older than X.
However, at least on Android, to access the offline storage via
OfflineManager.getInstance()
, it is necessary to first callMapLibre.getInstance()
. The latter can only be done on the UI thread. This means, that it is not possible to do this in aWorker
(when the app is not running), as there is no UI thread. (To not slow down startup nor download, StreetComplete does not trigger a cleanup of old data on startup but instead defers it to later, when the smartphone has nothing else to do, via theWorkManager
)Additional context
https://github.com/Helium314/SCEE/pull/516#issuecomment-2061993628 crash issues when trying to manually clear old tiles in a worker.