예제 #1
0
 public function getMetrics($domain)
 {
     $cacheId = 'SEO_getRank_' . md5($domain);
     $metrics = $this->cache->fetch($cacheId);
     if (!is_array($metrics)) {
         $metrics = $this->provider->getMetrics($domain);
         $this->cache->save($cacheId, $metrics, 60 * 60 * 6);
     }
     return $metrics;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function load($language, array $directories)
 {
     if (empty($language)) {
         return array();
     }
     $cacheKey = $this->getCacheKey($language, $directories);
     $translations = $this->cache->fetch($cacheKey);
     if (empty($translations) || !is_array($translations)) {
         $translations = $this->loader->load($language, $directories);
         $this->cache->save($cacheKey, $translations, 43200);
         // ttl=12hours
     }
     return $translations;
 }
예제 #3
0
파일: Client.php 프로젝트: piwik/piwik
 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;
 }
예제 #4
0
파일: Cache.php 프로젝트: cemo/piwik
 /**
  * @param $valueToMatch
  * @param $sql
  * @return array of IDs, or null if the returnset is too big to cache
  */
 private function getIdsFromCache($valueToMatch, $sql)
 {
     $cacheKey = $this->getCacheKey($valueToMatch, $sql);
     if ($this->cache->contains($cacheKey) === true) {
         // TODO: hits
         $this->logger->debug("Segment subquery cache HIT (for '{$valueToMatch}' and SQL '{$sql})");
         return $this->cache->fetch($cacheKey);
     }
     $ids = $this->fetchActionIdsFromDb($valueToMatch, $sql);
     if ($this->isTooBigToCache($ids)) {
         $this->logger->debug("Segment subquery cache SKIPPED SAVE (too many IDs returned by subquery: %s ids)'", array(count($ids)));
         $this->cache->save($cacheKey, $ids = null, $this->lifetime);
         return null;
     }
     $this->cache->save($cacheKey, $ids, $this->lifetime);
     $this->logger->debug("Segment subquery cache SAVE (for '{$valueToMatch}' and SQL '{$sql}')'");
     return $ids;
 }