wpdatatables
/
lib
/
phpoffice
/
phpspreadsheet
/
src
/
PhpSpreadsheet
/
Collection
/
Memory
/
SimpleCache3.php
SimpleCache3.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpSpreadsheet\Collection\Memory; |
| 4 | |
| 5 | use DateInterval; |
| 6 | use Psr\SimpleCache\CacheInterface; |
| 7 | |
| 8 | /** |
| 9 | * This is the default implementation for in-memory cell collection. |
| 10 | * |
| 11 | * Alternatives implementation should leverage off-memory, non-volatile storage |
| 12 | * to reduce overall memory usage. |
| 13 | */ |
| 14 | class SimpleCache3 implements CacheInterface |
| 15 | { |
| 16 | /** |
| 17 | * @var array Cell Cache |
| 18 | */ |
| 19 | private $cache = []; |
| 20 | |
| 21 | public function clear(): bool |
| 22 | { |
| 23 | $this->cache = []; |
| 24 | |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @param string $key |
| 30 | */ |
| 31 | public function delete($key): bool |
| 32 | { |
| 33 | unset($this->cache[$key]); |
| 34 | |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param iterable $keys |
| 40 | */ |
| 41 | public function deleteMultiple($keys): bool |
| 42 | { |
| 43 | foreach ($keys as $key) { |
| 44 | $this->delete($key); |
| 45 | } |
| 46 | |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @param string $key |
| 52 | * @param mixed $default |
| 53 | */ |
| 54 | public function get($key, $default = null): mixed |
| 55 | { |
| 56 | if ($this->has($key)) { |
| 57 | return $this->cache[$key]; |
| 58 | } |
| 59 | |
| 60 | return $default; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @param iterable $keys |
| 65 | * @param mixed $default |
| 66 | */ |
| 67 | public function getMultiple($keys, $default = null): iterable |
| 68 | { |
| 69 | $results = []; |
| 70 | foreach ($keys as $key) { |
| 71 | $results[$key] = $this->get($key, $default); |
| 72 | } |
| 73 | |
| 74 | return $results; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @param string $key |
| 79 | */ |
| 80 | public function has($key): bool |
| 81 | { |
| 82 | return array_key_exists($key, $this->cache); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @param string $key |
| 87 | * @param mixed $value |
| 88 | * @param null|DateInterval|int $ttl |
| 89 | */ |
| 90 | public function set($key, $value, $ttl = null): bool |
| 91 | { |
| 92 | $this->cache[$key] = $value; |
| 93 | |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @param iterable $values |
| 99 | * @param null|DateInterval|int $ttl |
| 100 | */ |
| 101 | public function setMultiple($values, $ttl = null): bool |
| 102 | { |
| 103 | foreach ($values as $key => $value) { |
| 104 | $this->set($key, $value); |
| 105 | } |
| 106 | |
| 107 | return true; |
| 108 | } |
| 109 | } |
| 110 |