X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FGithub%2FAPI%2FCall.php;h=d4afd19eeb3c375408162728293622a2f2e2b12c;hb=eb76e9bb9a39fe2725301f6cf6fc3cf29bbc4e00;hp=32bf1cb0c89bd7e46aa9c0ad70727c55fb8afd06;hpb=beaa328995cb2a32871259978d8da4acb3dc7715;p=pharext%2Fpharext.org diff --git a/app/Github/API/Call.php b/app/Github/API/Call.php index 32bf1cb..d4afd19 100644 --- a/app/Github/API/Call.php +++ b/app/Github/API/Call.php @@ -3,6 +3,7 @@ namespace app\Github\API; use app\Github\API; +use app\Github\Storage\Item; use http\QueryString; use http\Url; use merry\Config; @@ -96,17 +97,33 @@ abstract class Call function getCacheKey() { $args = $this->args; unset($args["fresh"]); + if (isset($args["page"]) && !strcmp($args["page"], "1")) { + unset($args["page"]); + } ksort($args); return sprintf("%s:%s:%s", $this->api->getToken(), $this, new QueryString($args)); } - function readFromCache(array &$cached = null, &$ttl = null) { - if (empty($this->args["fresh"]) && ($cache = $this->api->getCacheStorage())) { - $key = $this->getCacheKey(); - return $cache->get($key, $cached, $ttl); + function readFromCache(array &$value = null) { + if (!empty($this->args["fresh"])) { + return false; + } + if (!($cache = $this->api->getCacheStorage())) { + return false; + } + if (!strlen($key = $this->getCacheKey())) { + return false; + } + if (!$cache->get($key, $cached)) { + return false; + } + if (null !== $this->api->getMaxAge() && $cached->getAge() > $this->api->getMaxAge()) { + return false; } - return false; + $this->api->getLogger()->debug("Cache-Hit: $this", $this->args); + $value = $cached->getValue(); + return true; } function saveToCache(array $fresh) { @@ -118,7 +135,7 @@ abstract class Call } $key = $this->getCacheKey(); - $cache->set($key, $fresh, $ttl); + $cache->set($key, new Item($fresh, $ttl)); } }