Fix: Tiles-Cache-Bust — versionierte PMTiles-URL + version-bewusstes Caching
'nur DACH auf Staging' Ursache: serve_tile schickte Cache-Control max-age=86400 OHNE Validator → Browser lieferte bis 24h die ALTEN PMTiles-Bytes (altes Directory) trotz Datei-Swap. Fix: - map-gl-style.js: tilesUrl() hängt ?v=TILES_VER an (Cache-Bust bei Tile-Deploy) - serve_tile: ?v vorhanden → max-age=1y immutable; ohne → max-age=60 (self-heal) + ETag - Makefile tiles-deploy zählt TILES_VER automatisch hoch + erinnert an Frontend-Deploy
This commit is contained in:
parent
80b56c32ab
commit
2a809a9a0b
8 changed files with 33 additions and 18 deletions
|
|
@ -396,7 +396,14 @@ async def serve_tile(filename: str, request: Request):
|
|||
if not os.path.isfile(path):
|
||||
return Response(status_code=404)
|
||||
file_size = os.path.getsize(path)
|
||||
base_headers = {"Accept-Ranges": "bytes", "Cache-Control": "public, max-age=86400"}
|
||||
_mtime = int(os.path.getmtime(path))
|
||||
_etag = f'"{file_size:x}-{_mtime:x}"'
|
||||
# Versionierte URL (?v=…) ist inhaltsstabil → lange + immutable cachen. OHNE Version nur kurz cachen,
|
||||
# damit ein Tile-Swap (gleiche URL, neuer Inhalt) sich innerhalb ~1 Min von selbst heilt — sonst
|
||||
# liefert der Browser bis zu 24h die alten PMTiles-Bytes (alte Abdeckung).
|
||||
_versioned = "v" in request.query_params
|
||||
_cache = "public, max-age=31536000, immutable" if _versioned else "public, max-age=60"
|
||||
base_headers = {"Accept-Ranges": "bytes", "Cache-Control": _cache, "ETag": _etag}
|
||||
if request.method == "HEAD":
|
||||
return Response(
|
||||
status_code=200, media_type="application/octet-stream",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue