Ajout du cache dans la gestion des tuiles pbf
This commit is contained in:
1 parent
c081a82da6
commit
4081851988
2 files changed
+37
-2
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
/src/Core/config.php
|
/src/Core/config.php
|
||||||
/public/medias/*
|
/public/medias/*
|
||||||
/public/_maps
|
/public/_maps
|
||||||
|
/public/cache/*
|
||||||
/public/_ressources/dump.sql
|
/public/_ressources/dump.sql
|
||||||
*.sublime-project
|
*.sublime-project
|
||||||
*.sublime-workspace
|
*.sublime-workspace
|
||||||
|
|||||||
@@ -151,11 +151,45 @@ switch ($controller->splitted_url[1]) {
|
|||||||
$x = intval($controller->splitted_url[3]);
|
$x = intval($controller->splitted_url[3]);
|
||||||
$y = intval(str_replace(".pbf", "", $controller->splitted_url[4]));
|
$y = intval(str_replace(".pbf", "", $controller->splitted_url[4]));
|
||||||
|
|
||||||
|
$cacheRoot = $config['public_folder'].'/cache/tiles';
|
||||||
|
$cacheDir = $cacheRoot . '/' . $z . '/' . $x;
|
||||||
|
$cacheFile = $cacheDir . '/' . $y . '.pbf';
|
||||||
|
|
||||||
|
// Cache hit
|
||||||
|
if (is_file($cacheFile)) {
|
||||||
|
header('Content-Type: application/x-protobuf');
|
||||||
|
header('Cache-Control: public, max-age=31536000, immutable');
|
||||||
|
header('X-Cache: HIT');
|
||||||
|
readfile($cacheFile);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache miss : on génère une fois
|
||||||
$pois = new Kabano\Pois();
|
$pois = new Kabano\Pois();
|
||||||
|
|
||||||
header("Content-Type: application/x-protobuf");
|
try {
|
||||||
|
$tile = $pois->getVectorTile($z, $x, $y);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(500);
|
||||||
|
echo 'Tile generation failed: ' . $e->getMessage();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
echo $pois->getVectorTile($z,$x,$y);
|
if (!is_dir($cacheDir)) {
|
||||||
|
mkdir($cacheDir, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$tmp = $cacheFile . '.tmp';
|
||||||
|
file_put_contents($tmp, $tile);
|
||||||
|
|
||||||
|
if (file_exists($tmp)) {
|
||||||
|
rename($tmp, $cacheFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
header('Content-Type: application/x-protobuf');
|
||||||
|
header('Cache-Control: public, max-age=31536000, immutable');
|
||||||
|
header('X-Cache: MISS');
|
||||||
|
echo $tile;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in new issue
Block a user