Search code examples
serverpostgistile

what is the best solution to store a tile cache ? in a file system or a database table?


I have already implemented a tile server using xyz tile system and geotools for rendering tile image,now i have to cache my tile image which is a png image 256*256(always) of size ,i am not using geowebcache because i think it 's not suitable for a webmapping application where features geometry and layer style can change daily,so i am using xyz systems instead of using bbox or wms requests, i find a good article on serving tiles as mvt (mapbox vector tiles) from postgis at https://medium.com/geolytix/xyz-dynamic-vector-tiles-created-on-the-fly-cached-and-updated-directly-in-postgis-37db33c31450,for my case unstead of caching an mvt i will cache a raster tile ,the same as a bytearray ex:

create table if not exists tile_cache
(
    z integer not null,
    x integer not null,
    y integer not null,
    mvt tile,
    bbox geometry(Polygon,4326),
    constraint tile_cache_x_y_pk
        primary key (z, x, y)
)
;

create index if not exists tile_cache_z_x_y_idx
    on tile_cache (z, x, y)
;

it will create an xyz index to speed up thinks, so i was wondering what is the best and faster solution ? Serving tiles from postgis table using xyz index or serving directly from file system.


Solution

  • i had the same situation and i think if you want to update your tiles postgis solution(medium article) is much faster and easier.

    but if you just want to read raster tiles as a static map, the file system solution is much faster and you can keep your data with some structure like {z(directory)}/{x(directory)}/{y(tile)} and i recommend to take a look at tippecanoe project. it's a perfect way for static map, even better than file system solution.

    if you just want to change styles any time you want i recommend to use vector tiles. it's so much faster.