Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a LoadMode property to tell MapCache how to load the tiles #21

Merged
merged 4 commits into from
Jul 19, 2020
Merged

Added a LoadMode property to tell MapCache how to load the tiles #21

merged 4 commits into from
Jul 19, 2020

Conversation

kkieffer
Copy link
Contributor

@kkieffer kkieffer commented May 7, 2020

Following up on discussion from #17 I did find that using two closures did not seem to work properly. So since you can only select from either server or cache I made this modification.

I was able to make this work for my local fork. I added a property called LoadMode that determines how loadTile(at path: MKTileOverlayPath... loads tiles. The user could change this mode dynamically depending on their use case, their network connection status, etc.

  • case always_server always fetches from server, updating cache. Useful when on unmetered and high bandwidth (eg. Wifi) connection. User always receives most recent data.

  • case cache_then_server is the current paradigm. Use the cache, unless not found, then fetch from server and update. Minimum amount of network access.

  • case cache_if_expired_then_server returns from cache if the cache file is new enough, otherwise fetch from server and update. This I left as a TODO because a method is needed to first retrieve the file date and compare it to .now minus some user supplied delta. This is useful if the user cares mostly about limiting network access, but will accept some loading of tiles from the server if the cache is too old.

  • case cache_only Only fetch from cache, never go out to server. Useful to completely eliminate any bandwidth usage (perhaps user is on a limited or expensive data connection - they want to just use their cache which they've presumably loaded up prior).

@merlos
Copy link
Owner

merlos commented May 9, 2020

Thanks @kkeiffer 👍

I am looking at it. I´ll merge it ASAP. I may refactor part of your code (for instance extract LoadMode to a file and use camelCase naming in the enum...

I think we can skip cache_if_expired_then_server and use only cache_then_server. If the cache supports expiration, then cache_then_server is the same but with an infinite expiration time.
I added #24 as a separate enhancement that should provide support for this scenario.

Also, I am thinking that to download a map region with RegionDownloader, to have a only_server mode that performs the download and then update the cache, but does not return the tile in case of failure when it is already in the cache. This mode may be useful if you want to download/refresh a whole map. In this case, if the download of the tile fails you want to know that the tile failed to potentially do some kind of retry. I added #23 as I noticed that RegionDownloaderdoes not provide the list of failed tiles.

@merlos
Copy link
Owner

merlos commented May 10, 2020

I added some changes. It still needs testing.

@merlos merlos merged commit 3d02135 into merlos:master Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants