Commit ed87bfe1 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Cache non 200 Status codes only for 30 seconds

parent de9c29ee
......@@ -88,7 +88,7 @@ class RequestFetcher extends Command
$answersRead = $status[0];
$messagesLeft = $status[1];
$newJobs = $this->checkNewJobs($operationsRunning, $messagesLeft);
if ($newJobs === 0 && $answersRead === 0) {
usleep(10 * 1000);
}
......@@ -148,18 +148,23 @@ class RequestFetcher extends Command
$infos = explode(";", $infos);
$resulthash = $infos[0];
$cacheDurationMinutes = intval($infos[1]);
if(curl_errno($info["handle"])){
Log::error(curl_error($info["handle"]));
}
$result = $this->parseResponse($info["handle"]);
Redis::pipeline(function ($pipe) use ($resulthash, $result, $cacheDurationMinutes) {
$pipe->lpush($resulthash, json_encode($result));
$pipe->expire($resulthash, 15);
});
// Cache non 200 Status codes only for 30 seconds
if(intval($result['http-code']) !== 200){
$cacheDurationMinutes = 0.5;
}
if ($cacheDurationMinutes > 0) {
try {
Cache::put($resulthash, $result, $cacheDurationMinutes * 60);
......@@ -186,7 +191,7 @@ class RequestFetcher extends Command
];
}
$httpResponse = \curl_multi_getcontent($ch);
if (empty($httpResponse)) {
return null;
}
......@@ -204,7 +209,7 @@ class RequestFetcher extends Command
$headers_arr[strtolower("{$matches[0]}")] = trim($matches[1]);
}
}
// Unzip if content-encoding is gzip
if(!empty($headers_arr["content-encoding"]) && strtolower($headers_arr["content-encoding"]) === "gzip"){
$body = gzdecode($body);
......@@ -220,7 +225,7 @@ class RequestFetcher extends Command
$sanitizedHeaders[$key] = $value;
}
}
$response = [
"http-code" => $httpcode,
"body" => base64_encode($body),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment