diff options
author | diosmosis <benaka@piwik.pro> | 2015-10-06 18:33:04 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-10-06 18:33:43 +0300 |
commit | 1407c5effb1def3a8d36f9427c74012d7acf8434 (patch) | |
tree | 23dfb7a7e5bb7038d30c139fbc5b6f902841ac49 /core | |
parent | 28e9b28588452df1838e9b18e9cab5539bb5f8b0 (diff) |
Remove need for TableLogAction\Cache::$hits property which is only used for tests by injecting cache implementation used and using mock in test.
Diffstat (limited to 'core')
-rw-r--r-- | core/Tracker/TableLogAction/Cache.php | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/core/Tracker/TableLogAction/Cache.php b/core/Tracker/TableLogAction/Cache.php index 3c7862c25c..ba078c570d 100644 --- a/core/Tracker/TableLogAction/Cache.php +++ b/core/Tracker/TableLogAction/Cache.php @@ -31,18 +31,17 @@ class Cache private $logger; /** - * for tests - * - * @var int + * @var \Piwik\Cache\Lazy */ - static public $hits = 0; + private $cache; - public function __construct(LoggerInterface $logger, Config $config) + public function __construct(LoggerInterface $logger, Config $config, \Piwik\Cache\Lazy $cache) { $this->isEnabled = (bool)$config->General['enable_segments_subquery_cache']; $this->limitActionIds = $config->General['segments_subquery_cache_limit']; $this->lifetime = $config->General['segments_subquery_cache_ttl']; $this->logger = $logger; + $this->cache = $cache; } /** @@ -94,24 +93,22 @@ class Cache */ private function getIdsFromCache($valueToMatch, $sql) { - $cache = $this->buildCache(); $cacheKey = $this->getCacheKey($valueToMatch, $sql); - if ($cache->contains($cacheKey) === true) { - self::$hits++; + if ($this->cache->contains($cacheKey) === true) { // TODO: hits $this->logger->debug("Segment subquery cache HIT (for '$valueToMatch' and SQL '$sql)"); - return $cache->fetch($cacheKey); + 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))); - $cache->save($cacheKey, $ids = null, $this->lifetime); + $this->cache->save($cacheKey, $ids = null, $this->lifetime); return null; } - $cache->save($cacheKey, $ids, $this->lifetime); + $this->cache->save($cacheKey, $ids, $this->lifetime); $this->logger->debug("Segment subquery cache SAVE (for '$valueToMatch' and SQL '$sql')'"); return $ids; @@ -153,14 +150,6 @@ class Cache } /** - * @return \Piwik\Cache\Lazy - */ - private function buildCache() - { - return \Piwik\Cache::getLazyCache(); - } - - /** * @param $ids * @return bool */ |