private function fetch($action, $params)
{
ksort($params);
// sort params so cache is reused more often even if param order is different
$releaseChannel = $this->environment->getReleaseChannel();
if (!empty($releaseChannel)) {
$params['release_channel'] = $releaseChannel;
}
$params['prefer_stable'] = (int) $this->environment->doesPreferStable();
$params['piwik'] = $this->environment->getPiwikVersion();
$params['php'] = $this->environment->getPhpVersion();
$params['mysql'] = $this->environment->getMySQLVersion();
$params['num_users'] = $this->environment->getNumUsers();
$params['num_websites'] = $this->environment->getNumWebsites();
$query = http_build_query($params);
$cacheId = $this->getCacheKey($action, $query);
$result = $this->cache->fetch($cacheId);
if ($result !== false) {
return $result;
}
try {
$result = $this->service->fetch($action, $params);
} catch (Service\Exception $e) {
throw new Exception($e->getMessage(), $e->getCode());
}
$this->cache->save($cacheId, $result, self::CACHE_TIMEOUT_IN_SECONDS);
return $result;
}