Skip to content
Snippets Groups Projects
Commit 75987d10 authored by Phil Höfer's avatar Phil Höfer
Browse files

Improve Quicktips caching

parent fdd1b34c
No related branches found
No related tags found
5 merge requests!1730Development,!1724Development,!1723Development,!1713Resolve "Add setting to enable darkmode",!1710Resolve "Add Quotes and Did-you-know to MetaGer"
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment