Example #1
0
File: Cache.php Project: 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;
 }