X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=app%2FGithub%2FAPI%2FCall.php;h=32bf1cb0c89bd7e46aa9c0ad70727c55fb8afd06;hb=47343850bc7ab2851d1c6633b65742c43a50d02e;hp=3615851693f1870d2094ea70d8a3a018298326f6;hpb=25b99959b9e66d00681092977c23b5df32ead5f4;p=pharext%2Fpharext.org diff --git a/app/Github/API/Call.php b/app/Github/API/Call.php index 3615851..32bf1cb 100644 --- a/app/Github/API/Call.php +++ b/app/Github/API/Call.php @@ -57,17 +57,12 @@ abstract class Call } function __invoke(callable $callback) { - if (empty($this->args["fresh"]) && ($cache = $this->api->getCacheStorage())) { - $key = $this->getCacheKey(); - - if ($cache->get($key, $cached)) { - call_user_func_array($callback, $cached); - return $this->api->getClient(); - } + if ($this->readFromCache($cached)) { + call_user_func_array($callback, $cached); + } else { + $this->enqueue($callback); } - - $this->enqueue($callback); - return $this->api->getClient(); + return $this; } /** @@ -79,6 +74,13 @@ abstract class Call return strtolower(end($parts)); } + /** + * Call Client::send() + */ + function send() { + return $this->api->getClient()->send(); + } + /** * Get associated cache storage * @param int $ttl out param of configure ttl @@ -92,8 +94,11 @@ abstract class Call } function getCacheKey() { - return sprintf("github:%s:%s:%s", $this->api->getToken(), $this, - new QueryString($this->args)); + $args = $this->args; + unset($args["fresh"]); + ksort($args); + return sprintf("%s:%s:%s", $this->api->getToken(), $this, + new QueryString($args)); } function readFromCache(array &$cached = null, &$ttl = null) { @@ -109,11 +114,18 @@ abstract class Call if (isset($this->config->storage->cache->{$this}->ttl)) { $ttl = $this->config->storage->cache->{$this}->ttl; } else { - $ttl = 0; + $ttl = null; } $key = $this->getCacheKey(); $cache->set($key, $fresh, $ttl); } } + + function dropFromCache() { + if (($cache = $this->api->getCacheStorage())) { + $key = $this->getCacheKey(); + $cache->del($key); + } + } }