From 75987d10715cc73ada3be3e5cfd9d20a77ddc646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phil=20H=C3=B6fer?= <phil@suma-ev.de> Date: Tue, 20 Oct 2020 14:13:17 +0200 Subject: [PATCH] Improve Quicktips caching --- app/Models/Quicktips/Quicktips.php | 41 +++++++++++++++++------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/app/Models/Quicktips/Quicktips.php b/app/Models/Quicktips/Quicktips.php index c8b14c273..0bfc673a8 100644 --- a/app/Models/Quicktips/Quicktips.php +++ b/app/Models/Quicktips/Quicktips.php @@ -32,24 +32,25 @@ class Quicktips $url = $this->quicktipUrl . "?search=" . $this->normalize_search($search) . "&locale=" . $locale; $this->hash = md5($url); - - if (!Redis::exists($this->hash)) { - - // Queue this search - $mission = [ - "resulthash" => $this->hash, - "url" => $url, - "useragent" => "", - "username" => null, - "password" => null, - "headers" => [], - "cacheDuration" => self::CACHE_DURATION, - "name" => "Quicktips", - ]; - - $mission = json_encode($mission); - - Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission); + if (!Cache::has($this->hash)) { + if (!Redis::exists($this->hash)) { + + // Queue this search + $mission = [ + "resulthash" => $this->hash, + "url" => $url, + "useragent" => "", + "username" => null, + "password" => null, + "headers" => [], + "cacheDuration" => self::CACHE_DURATION, + "name" => "Quicktips", + ]; + + $mission = json_encode($mission); + + Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission); + } } } @@ -76,6 +77,10 @@ class Quicktips $startTime = microtime(true); + if ($cache::has($this->hash)) { + return Cache::get($this->hash, false); + } + while (microtime(true) - $startTime < 0.5) { $body = Redis::rpoplpush($this->hash, $this->hash); if ($body === false || $body === null) { -- GitLab