| Total Complexity | 12 |
| Total Lines | 99 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class ArrayCache extends CacheProvider |
||
| 13 | { |
||
| 14 | /** @var array[] $data each element being a tuple of [$data, $expiration], where the expiration is int|bool */ |
||
| 15 | private $data = []; |
||
| 16 | |||
| 17 | /** @var int */ |
||
| 18 | private $hitsCount = 0; |
||
| 19 | |||
| 20 | /** @var int */ |
||
| 21 | private $missesCount = 0; |
||
| 22 | |||
| 23 | /** @var int */ |
||
| 24 | private $upTime; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * {@inheritdoc} |
||
| 28 | */ |
||
| 29 | public function __construct() |
||
| 30 | { |
||
| 31 | $this->upTime = time(); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | protected function doFetch($id) |
||
| 38 | { |
||
| 39 | if (! $this->doContains($id)) { |
||
| 40 | $this->missesCount += 1; |
||
| 41 | |||
| 42 | return false; |
||
| 43 | } |
||
| 44 | |||
| 45 | $this->hitsCount += 1; |
||
| 46 | |||
| 47 | return $this->data[$id][0]; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * {@inheritdoc} |
||
| 52 | */ |
||
| 53 | protected function doContains($id) |
||
| 54 | { |
||
| 55 | if (! isset($this->data[$id])) { |
||
| 56 | return false; |
||
| 57 | } |
||
| 58 | 157 | ||
| 59 | $expiration = $this->data[$id][1]; |
||
| 60 | 157 | ||
| 61 | 157 | if ($expiration && $expiration < time()) { |
|
| 62 | $this->doDelete($id); |
||
| 63 | |||
| 64 | return false; |
||
| 65 | } |
||
| 66 | 142 | ||
| 67 | return true; |
||
| 68 | 142 | } |
|
| 69 | 78 | ||
| 70 | /** |
||
| 71 | 78 | * {@inheritdoc} |
|
| 72 | */ |
||
| 73 | protected function doSave($id, $data, $lifeTime = 0) |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | 153 | */ |
|
| 83 | protected function doDelete($id) |
||
| 88 | 141 | } |
|
| 89 | |||
| 90 | 141 | /** |
|
| 91 | 2 | * {@inheritdoc} |
|
| 92 | */ |
||
| 93 | 2 | protected function doFlush() |
|
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * {@inheritdoc} |
||
| 102 | 149 | */ |
|
| 103 | protected function doGetStats() |
||
| 111 | ]; |
||
| 112 | 93 | } |
|
| 113 | } |
||
| 114 |