diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-12-17 00:25:51 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-12-17 00:25:51 +0300 |
commit | 1634607051341f6d348404cd4bc478cf2474a259 (patch) | |
tree | 8893897d8cdb2b5313a3a2f3f6fac39ce1b56755 /core/DeviceDetectorCache.php | |
parent | c0f24c160ab2f573a06146c66fa7fc7bab97a3a7 (diff) |
added support for different caching backends such as redis
Diffstat (limited to 'core/DeviceDetectorCache.php')
-rw-r--r-- | core/DeviceDetectorCache.php | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/core/DeviceDetectorCache.php b/core/DeviceDetectorCache.php index ba65b82c9f..c337b1b0a4 100644 --- a/core/DeviceDetectorCache.php +++ b/core/DeviceDetectorCache.php @@ -8,6 +8,7 @@ */ namespace Piwik; +use Piwik\Cache as PiwikCache; use Exception; /** @@ -17,10 +18,19 @@ use Exception; * * Static caching speeds up multiple detections in one request, which is the case when sending bulk requests */ -class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\CacheInterface +class DeviceDetectorCache implements \DeviceDetector\Cache\CacheInterface { protected static $staticCache = array(); + private $cache; + private $ttl; + + public function __construct($ttl = 300) + { + $this->ttl = (int) $ttl; + $this->cache = PiwikCache::getLazyCache(); + } + /** * Function to fetch a cache entry * @@ -33,13 +43,11 @@ class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\Cac return false; } - $id = $this->cleanupId($id); - if (array_key_exists($id, self::$staticCache)) { return self::$staticCache[$id]; } - return parent::get($id); + return $this->cache->fetch($id); } /** @@ -56,10 +64,9 @@ class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\Cac return false; } - $id = $this->cleanupId($id); - self::$staticCache[$id] = $content; - return parent::set($id, $content); + return $this->cache->save($id, $content, $this->ttl); } + } |