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

Caching of tiles? #26

Open
kezara opened this issue Oct 22, 2021 · 5 comments
Open

Caching of tiles? #26

kezara opened this issue Oct 22, 2021 · 5 comments

Comments

@kezara
Copy link

kezara commented Oct 22, 2021

I have only 1 year of professional experience in programming, so this is maybe stupid one, why not caching tiles in Dictionary<string, BitmapSource>, where string would be fileName, and then limit number of entries on, let's say 5000, and then create new instance of dictionary?
I actually tried this (only a few times), in Render class I implemented static dictionary and in RenderCached method I create instance of it, but with mbtiles file of only 153 MB and it worked quite well...
I'd like to use this library, but with extracts, I'm not sure, but probably in size of the city, maybe country, so would this be possible?
As I said, I do not have much experience, so I do not know how will this impact on memory and CPU consumption, but is this plausible?

@rbrundritt
Copy link

rbrundritt commented Oct 22, 2021

There are lots of different ways to cache tiles depending on the app/service you are creating. This library is primarily focused on the rendering aspect of vector tiles, so built in caching should be limited as there may be scenarios where it isn't wanted/needed (i.e. dynamic tile service that needs to always render the latest version of a tile that might change several times a minute).

Using a dictionary is a good simple cache solution for smaller tile sets and apps that run on a client. Memory usage would need to be watched as that's where these tiles will be cached. In a server side solution this may not work well if there is a large number of tiles in the data set, and you have a lot of users accessing your server.

Another solution for larger data sets is cache the tiles in a sqlite database. There is a common specification used for storing tiles (raster and vector) in such a database called MBTiles (this basically just tells you two tables to have in the database so that there is consistency between sqlite databases storing tiles for easier reuse and tooling creation). Using this solution, will be slightly slower at reading (milliseconds), but will use a lot less memory. Writing to a sqlite database is a lot faster than writing to disk as well.

When it comes to server side caching with multiple servers spread out globally, there are much more advance caching strategies that can be used.

@AliFlux
Copy link
Owner

AliFlux commented Oct 22, 2021

Yeah, in-memory caching can easily hog up the RAM. There are various options for caching such as:

  • Using mbtiles (as @rbrundritt mentioned)
  • Using redis/memcached (usually for serverside distributed rendering)
  • Storing in plain files (implemented right now)
  • Storing in-memory (LRU/LFU caching)
  • Storing in a DB like PostGIS (DB overhead)

Depending on your use-case, you may modify the code to implement that specific strategy. Look at the RenderCached function in Renderer.cs for headstart

@ShawnStoddard
Copy link

ShawnStoddard commented Oct 24, 2021 via email

@AliFlux
Copy link
Owner

AliFlux commented Oct 25, 2021

The caching system is already implemented. The RenderCached function does exactly that. It renders a map once, saves it to a file. And when its invoked again it reads the rendered copy instead instead of re-rendering it.

You can specify where you want the cached images saved. Simply set the cachePath parameter of this function.

P.S. In Mapsui and Gmap, you can check the demo source codes to see where the cache path is specified.

@kezara
Copy link
Author

kezara commented Oct 26, 2021

Where are the tiles being generated? It is amazing how this general problem has crept in. I’m working on a project needs to access cached copy of raster map tiles. I’m trying to cache images plus generate them. To work around generating the letting open street maps. Once we retrieve the original image we can stop accessing them. A background process can update these.

On Fri, Oct 22, 2021, at 13:10, Borisav Ignjatov wrote: I have only 1 year of professional experience in programming, so this is maybe stupid one, why not caching tiles in Dictionary<string, BitmapSource>, where string would be fileName, and then limit number of entries on, let's say 5000, and then create new instance of dictionary? I actually tried this (only a few times), in Render class I implemented static dictionary and in RenderCached method I create instance of it, but with mbtiles file of only 153 MB and it worked quite well... I'd like to use this library, but with extracts, I'm not sure, but probably in size of the city, maybe country, so would this be possible? As I said, I do not have much experience, so I do not know how will this impact on memory and CPU consumption, but is this plausible? — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#26>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARTX7JASLVDPNSXEQLJ3ODUIGLJFANCNFSM5GRACQRA.

I need maps for offline desktop application, and maps are smaller part of it, so I think to use ready made solutions, so I first make extracts with osmium tool and for generation of tiles I have 2 options in mind, one is TileMaker which generates vector mbtiles, and second is Maperitive which makes raster mbtiles or png tiles....

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

No branches or pull requests

4 participants