Version qui gère mieux les écritures concurentes dans le cache
This commit is contained in:
1 parent
117e4935f5
commit
cf36496e0f
1 file changed
+19
-9
@@ -151,7 +151,7 @@ switch ($controller->splitted_url[1]) {
|
||||
$x = intval($controller->splitted_url[3]);
|
||||
$y = intval(str_replace(".pbf", "", $controller->splitted_url[4]));
|
||||
|
||||
$cacheRoot = $config['public_folder'].'/cache/tiles';
|
||||
$cacheRoot = $config['public_folder'] . '/cache/tiles';
|
||||
$cacheDir = $cacheRoot . '/' . $z . '/' . $x;
|
||||
$cacheFile = $cacheDir . '/' . $y . '.pbf';
|
||||
|
||||
@@ -164,7 +164,19 @@ switch ($controller->splitted_url[1]) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Cache miss : on génère une fois
|
||||
// Création du dossier si nécessaire
|
||||
if (!is_dir($cacheDir)) {
|
||||
if (!@mkdir($cacheDir, 0777, true) && !is_dir($cacheDir)) {
|
||||
http_response_code(500);
|
||||
exit('Tile cache directory not writable');
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_writable($cacheDir)) {
|
||||
http_response_code(500);
|
||||
exit('Tile cache directory is not writable');
|
||||
}
|
||||
|
||||
$pois = new Kabano\Pois();
|
||||
|
||||
try {
|
||||
@@ -175,16 +187,14 @@ switch ($controller->splitted_url[1]) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_dir($cacheDir)) {
|
||||
mkdir($cacheDir, 0777, true);
|
||||
$tmp = $cacheDir . '/' . uniqid('tile_', true) . '.pbf.tmp';
|
||||
|
||||
if (file_put_contents($tmp, $tile) === false) {
|
||||
http_response_code(500);
|
||||
exit('Unable to write tile cache');
|
||||
}
|
||||
|
||||
$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');
|
||||
|
||||
Reference in new issue
Block a user