ArrayCache.php
979 字节
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
<?php
namespace Symfony\Component\Cache\Tests\Fixtures;
use Doctrine\Common\Cache\CacheProvider;
class ArrayCache extends CacheProvider
{
private $data = [];
protected function doFetch($id)
{
return $this->doContains($id) ? $this->data[$id][0] : false;
}
protected function doContains($id)
{
if (!isset($this->data[$id])) {
return false;
}
$expiry = $this->data[$id][1];
return !$expiry || microtime(true) < $expiry || !$this->doDelete($id);
}
protected function doSave($id, $data, $lifeTime = 0)
{
$this->data[$id] = [$data, $lifeTime ? microtime(true) + $lifeTime : false];
return true;
}
protected function doDelete($id)
{
unset($this->data[$id]);
return true;
}
protected function doFlush()
{
$this->data = [];
return true;
}
protected function doGetStats()
{
return null;
}
}