1 | <?php |
||
42 | class ArrayCache extends SimpleCache |
||
43 | { |
||
44 | /** |
||
45 | * @var array cached values. |
||
46 | */ |
||
47 | private $_cache = []; |
||
48 | |||
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 6 | public function has($key) |
|
54 | { |
||
55 | 6 | $key = $this->normalizeKey($key); |
|
56 | 6 | return isset($this->_cache[$key]) && ($this->_cache[$key][1] === 0 || $this->_cache[$key][1] > microtime(true)); |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * @inheritdoc |
||
61 | */ |
||
62 | 48 | protected function getValue($key) |
|
63 | { |
||
64 | 48 | if (isset($this->_cache[$key]) && ($this->_cache[$key][1] === 0 || $this->_cache[$key][1] > microtime(true))) { |
|
65 | 40 | return $this->_cache[$key][0]; |
|
66 | } |
||
67 | 36 | return false; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * @inheritdoc |
||
72 | */ |
||
73 | 48 | protected function setValue($key, $value, $ttl) |
|
74 | { |
||
75 | 48 | $this->_cache[$key] = [$value, $ttl === 0 ? 0 : microtime(true) + $ttl]; |
|
76 | 48 | return true; |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | 3 | protected function deleteValue($key) |
|
87 | |||
88 | /** |
||
89 | * @inheritdoc |
||
90 | */ |
||
91 | 14 | public function clear() |
|
96 | } |
||
97 |