Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik;
use Exception;
/**
* Caching class used for DeviceDetector caching
*
* Combines Piwik\CacheFile with an additional caching in static property
*
* Static caching speeds up multiple detections in one request, which is mostly the case when importing logs
*/
class DeviceDetectorCache extends CacheFile implements \DeviceDetector\Cache\CacheInterface
{
protected static $staticCache = array();
/**
* Function to fetch a cache entry
*
* @param string $id The cache entry ID
* @return array|bool False on error, or array the cache content
*/
public function get($id)
{
if (empty($id)) {
return false;
}
$id = $this->cleanupId($id);
if (array_key_exists($id, self::$staticCache)) {
return self::$staticCache[$id];
}
return parent::get($id);
}
/**
* A function to store content a cache entry.
*
* @param string $id The cache entry ID
* @param array $content The cache content
* @throws \Exception
* @return bool True if the entry was succesfully stored
*/
public function set($id, $content)
{
if (empty($id)) {
return false;
}
$id = $this->cleanupId($id);
self::$staticCache[$id] = $content;
return parent::set($id, $content);
}
}