Coverage for gws-app/gws/gis/cache/__init__.py: 100%
2 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Tile cache management.
3This package holds the tile cache configuration, the filesystem tile store
4used by grabbers, and the tools to inspect, seed and drop caches.
6Tiles are produced and stored by grabbers (``gws.base.grabber``). Every
7grabber of an image layer has a persistent store (``store.Object``) in a
8directory under ``MAP_CACHE_DIR``, named after the grabber's cache name.
9Layers with identical source bindings share one cache. This package works on
10these stores from the outside: it collects all caches of a configuration
11into an inventory, filters it and then reads statistics, removes tiles or
12fills the cache by requesting tiles from the grabbers.
14Submodules:
16- ``core``: the config classes ``LayerConfig`` (per layer ``cache`` option)
17 and ``GlobalConfig`` (application ``cache`` option), the inventory data
18 structures (``Inventory``, ``Cache``, ``Level``, ``Filter``) and the
19 functions to build, filter and drop an inventory, remove orphan cache
20 directories and write to the web cache.
21- ``store``: the filesystem tile store, which implements ``gws.TileStore``
22 with the MapProxy ``mp`` directory layout
23 (``<level>/<x div 10000>/<x mod 10000>/<y div 10000>/<y mod 10000>.<ext>``).
24 A tile counts as stored while its file is younger than the max. age.
25 Empty files and ``.tmp`` files are not counted in statistics.
26- ``seed``: cache seeding. Missing tiles are requested from the grabbers in
27 blocks, by a number of worker threads, until all are done or the time
28 limit is reached. Only one seeding run can be active at a time.
29- ``cli``: the ``gws cache`` command line commands ``status``,
30 ``cleanup``, ``drop`` and ``seed``.
32Example::
34 gws cache status --details
35 gws cache seed --layerUids my_layer --levels 0-12
36 gws cache drop --crs 3857 --bbox 1000,2000,3000,4000 --levels 14
38Configuration example, a layer cache and the global seeding options::
40 map.layers+ {
41 type "wms"
42 provider.url "https://example.com/wms"
43 cache { maxAge "30d" maxLevel 16 }
44 }
46 cache { seedingMaxTime "1h" seedingConcurrency 4 }
48Python usage example::
50 import gws.gis.cache.core as core
52 inv = core.inventory(root)
53 core.apply_filter(inv, core.Filter(cacheNames=['abc'], levels=[0, 1, 2]))
54 core.add_stats(inv)
55 for c in inv.caches:
56 print(c.name, c.cachedTiles, core.percentage_by_level(c))
57"""
59from .core import (
60 GlobalConfig,
61 LayerConfig,
62 store_in_web_cache,
63)
64from . import store