Version qui gère mieux les écritures concurentes dans le cache
This commit is contained in:
1 parent
117e4935f5
commit
cf36496e0f
1 file changed
+18
-8
@@ -164,7 +164,19 @@ switch ($controller->splitted_url[1]) {
|
|||||||
exit;
|
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();
|
$pois = new Kabano\Pois();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -175,16 +187,14 @@ switch ($controller->splitted_url[1]) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_dir($cacheDir)) {
|
$tmp = $cacheDir . '/' . uniqid('tile_', true) . '.pbf.tmp';
|
||||||
mkdir($cacheDir, 0777, true);
|
|
||||||
|
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);
|
rename($tmp, $cacheFile);
|
||||||
}
|
|
||||||
|
|
||||||
header('Content-Type: application/x-protobuf');
|
header('Content-Type: application/x-protobuf');
|
||||||
header('Cache-Control: public, max-age=31536000, immutable');
|
header('Cache-Control: public, max-age=31536000, immutable');
|
||||||
|
|||||||
Reference in new issue
Block a user