| 1 | <?php |
||
| 7 | final class CacheMap implements CacheMapInterface, \Countable |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | private $cache = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * {@inheritdoc} |
||
| 16 | */ |
||
| 17 | 35 | public function get($key) |
|
| 18 | { |
||
| 19 | 35 | $index = $this->findCacheIndexByKey($key); |
|
| 20 | |||
| 21 | 35 | if ($index === null) { |
|
| 22 | 32 | return false; |
|
| 23 | } |
||
| 24 | |||
| 25 | 14 | return $this->cache[$index]['value']; |
|
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | 35 | public function set($key, $value): void |
|
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | 13 | public function delete($key): void |
|
| 52 | { |
||
| 53 | 13 | $index = $this->findCacheIndexByKey($key); |
|
| 54 | 13 | unset($this->cache[$index]); |
|
| 55 | 13 | } |
|
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | 2 | public function clear(): void |
|
| 61 | { |
||
| 62 | 2 | $this->cache = []; |
|
| 63 | 2 | } |
|
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | 2 | public function count(): int |
|
| 69 | { |
||
| 70 | 2 | return \count($this->cache); |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Returns the index of the value from the cache array with the given key. |
||
| 75 | * |
||
| 76 | * @param mixed $cacheKey |
||
| 77 | * |
||
| 78 | * @return mixed |
||
| 79 | */ |
||
| 80 | 37 | private function findCacheIndexByKey($cacheKey) |
|
| 88 | } |
||
| 89 |