| 1 |
<?php |
| 2 |
|
| 3 |
namespace PhpOffice\PhpSpreadsheet\Collection; |
| 4 |
|
| 5 |
use Psr\SimpleCache\CacheInterface; |
| 6 |
|
| 7 |
/** |
| 8 |
* This is the default implementation for in-memory cell collection. |
| 9 |
* |
| 10 |
* Alternatives implementation should leverage off-memory, non-volatile storage |
| 11 |
* to reduce overall memory usage. |
| 12 |
*/ |
| 13 |
class Memory implements CacheInterface |
| 14 |
{ |
| 15 |
private $cache = []; |
| 16 |
|
| 17 |
public function clear() |
| 18 |
{ |
| 19 |
$this->cache = []; |
| 20 |
|
| 21 |
return true; |
| 22 |
} |
| 23 |
|
| 24 |
public function delete($key) |
| 25 |
{ |
| 26 |
unset($this->cache[$key]); |
| 27 |
|
| 28 |
return true; |
| 29 |
} |
| 30 |
|
| 31 |
public function deleteMultiple($keys) |
| 32 |
{ |
| 33 |
foreach ($keys as $key) { |
| 34 |
$this->delete($key); |
| 35 |
} |
| 36 |
|
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
public function get($key, $default = null) |
| 41 |
{ |
| 42 |
if ($this->has($key)) { |
| 43 |
return $this->cache[$key]; |
| 44 |
} |
| 45 |
|
| 46 |
return $default; |
| 47 |
} |
| 48 |
|
| 49 |
public function getMultiple($keys, $default = null) |
| 50 |
{ |
| 51 |
$results = []; |
| 52 |
foreach ($keys as $key) { |
| 53 |
$results[$key] = $this->get($key, $default); |
| 54 |
} |
| 55 |
|
| 56 |
return $results; |
| 57 |
} |
| 58 |
|
| 59 |
public function has($key) |
| 60 |
{ |
| 61 |
return array_key_exists($key, $this->cache); |
| 62 |
} |
| 63 |
|
| 64 |
public function set($key, $value, $ttl = null) |
| 65 |
{ |
| 66 |
$this->cache[$key] = $value; |
| 67 |
|
| 68 |
return true; |
| 69 |
} |
| 70 |
|
| 71 |
public function setMultiple($values, $ttl = null) |
| 72 |
{ |
| 73 |
foreach ($values as $key => $value) { |
| 74 |
$this->set($key, $value); |
| 75 |
} |
| 76 |
|
| 77 |
return true; |
| 78 |
} |
| 79 |
} |
| 80 |
|