| <?php |
|
|
| |
| |
| |
| |
| |
| |
|
|
| namespace Piwik\DeviceDetector; |
|
|
| use Piwik\Cache as PiwikCache; |
|
|
| |
| |
| |
| |
| |
| |
| |
| 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(); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| public function fetch($id) |
| { |
| if (empty($id)) { |
| return false; |
| } |
|
|
| if (array_key_exists($id, self::$staticCache)) { |
| return self::$staticCache[$id]; |
| } |
|
|
| if (!$this->cache->contains($id)) { |
| return false; |
| } |
|
|
| return $this->cache->fetch($id); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| public function save($id, $content, $ttl = 0): bool |
| { |
| if (empty($id)) { |
| return false; |
| } |
|
|
| self::$staticCache[$id] = $content; |
|
|
| return (bool) $this->cache->save($id, $content, $this->ttl); |
| } |
|
|
| public function contains($id): bool |
| { |
| return !empty(self::$staticCache[$id]) && $this->cache->contains($id); |
| } |
|
|
| public function delete($id): bool |
| { |
| if (empty($id)) { |
| return false; |
| } |
|
|
| unset(self::$staticCache[$id]); |
|
|
| return (bool) $this->cache->delete($id); |
| } |
|
|
| public function flushAll(): bool |
| { |
| return (bool) $this->cache->flushAll(); |
| } |
| } |
|
|