diff --git a/app/CacheHelper.php b/app/CacheHelper.php new file mode 100644 index 0000000000000000000000000000000000000000..16e9b77a8fe4953df99251d3a305a898bc5ae70b --- /dev/null +++ b/app/CacheHelper.php @@ -0,0 +1,22 @@ + $time, + 'key' => $key, + 'value' => $value, + ]; + Redis::rpush(\App\Console\Commands\RequestCacher::CACHER_QUEUE, json_encode($cacherItem)); + + } +} diff --git a/app/Console/Commands/RequestFetcher.php b/app/Console/Commands/RequestFetcher.php index b2fc6431af85f441cb37912a01cb87faca69b281..c96a6d9bbd460debfe632e809dd62eb594f2dc6b 100644 --- a/app/Console/Commands/RequestFetcher.php +++ b/app/Console/Commands/RequestFetcher.php @@ -97,7 +97,7 @@ class RequestFetcher extends Command $infos = curl_getinfo($info["handle"], CURLINFO_PRIVATE); $infos = explode(";", $infos); $resulthash = $infos[0]; - $cacheDuration = intval($infos[1]); + $cacheDurationMinutes = intval($infos[1]); $responseCode = curl_getinfo($info["handle"], CURLINFO_HTTP_CODE); $body = ""; @@ -112,17 +112,16 @@ class RequestFetcher extends Command $body = \curl_multi_getcontent($info["handle"]); } - Redis::pipeline(function ($pipe) use ($resulthash, $body, $cacheDuration) { + Redis::pipeline(function ($pipe) use ($resulthash, $body, $cacheDurationMinutes) { $pipe->set($resulthash, $body); $pipe->expire($resulthash, 60); $cacherItem = [ - 'cacheDuration' => $cacheDuration, - 'hash' => $resulthash, - 'body' => $body, + 'timeSeconds' => $cacheDurationMinutes * 60, + 'key' => $resulthash, + 'value' => $body, ]; $pipe->rpush(\App\Console\Commands\RequestCacher::CACHER_QUEUE, json_encode($cacherItem)); }); - #Cache::put($resulthash, $body, now()->addMinutes($cacheDuration)); \curl_multi_remove_handle($this->multicurl, $info["handle"]); } if (!$active && !$answerRead) { diff --git a/app/Http/Middleware/HumanVerification.php b/app/Http/Middleware/HumanVerification.php index f9cad046f7d66a9323acbf4230d37b36bd842d0d..f7c61dc15b4736cec50de395a483a38ebbcdeb16 100644 --- a/app/Http/Middleware/HumanVerification.php +++ b/app/Http/Middleware/HumanVerification.php @@ -50,7 +50,7 @@ class HumanVerification # Get all Users of this IP $users = Cache::get($prefix . "." . $id, []); - $users = $this->removeOldUsers($users); + $users = $this->removeOldUsers($prefix, $users); $user = []; if (empty($users[$uid])) { @@ -148,10 +148,10 @@ class HumanVerification // Lock must be acquired within 2 seconds $userList = Cache::get($prefix . "." . $user["id"], []); $userList[$user["uid"]] = $user; - Cache::put($prefix . "." . $user["id"], $userList, now()->addWeeks(2)); + \App\CacheHelper::put($prefix . "." . $user["id"], $userList, 2 * 7 * 24 * 60 * 60); } - public function removeOldUsers($userList) + public function removeOldUsers($prefix, $userList) { $newUserlist = []; $now = now(); @@ -168,10 +168,7 @@ class HumanVerification } if ($changed) { - // Lock must be acquired within 2 seconds - Cache::lock($prefix . "." . $user["id"])->block(2, function () { - Cache::put($prefix . "." . $user["id"], $newUserlist, now()->addWeeks(2)); - }); + \App\CacheHelper::put($prefix . "." . $user["id"], $newUserlist, 2 * 7 * 24 * 60 * 60); } return $newUserlist; diff --git a/app/MetaGer.php b/app/MetaGer.php index c9c102dc578192ad1b12c0b7497c2ce80df5ca19..63c9f5e6871b88075feb406d6509c9cffa315b6f 100644 --- a/app/MetaGer.php +++ b/app/MetaGer.php @@ -323,7 +323,7 @@ class MetaGer 'page' => $page, 'engines' => $this->next, ]; - Cache::put($this->getSearchUid(), serialize($this->next), 60); + \App\CacheHelper::put($this->getSearchUid(), serialize($this->next), 60 * 60); } else { $this->next = []; }