| Total Complexity | 11 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 44.44% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class FileCache implements CacheInterface |
||
| 10 | { |
||
| 11 | 3 | public function __construct(protected string $cacheFilePath, protected int $ttl) |
|
| 12 | { |
||
| 13 | 3 | } |
|
| 14 | |||
| 15 | 3 | public function get(string $key, mixed $default = null): mixed |
|
| 16 | { |
||
| 17 | 3 | return ($this->has($key)) ? file_get_contents($this->cacheFilePath) : $default; |
|
| 18 | } |
||
| 19 | |||
| 20 | 3 | public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool |
|
| 21 | { |
||
| 22 | 3 | return (bool) file_put_contents($this->cacheFilePath, $value); |
|
| 23 | } |
||
| 24 | |||
| 25 | 3 | public function has(string $key): bool |
|
| 26 | { |
||
| 27 | 3 | return file_exists($this->cacheFilePath) && time() - filemtime($this->cacheFilePath) < $this->ttl; |
|
| 28 | } |
||
| 29 | |||
| 30 | public function delete(string $key): bool |
||
| 31 | { |
||
| 32 | return unlink($this->cacheFilePath); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function clear(): bool |
||
| 36 | { |
||
| 37 | return $this->delete($this->cacheFilePath); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function getMultiple(iterable $keys, mixed $default = null): iterable |
||
| 43 | } |
||
| 44 | |||
| 45 | public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool |
||
| 46 | { |
||
| 47 | return false; |
||
| 48 | } |
||
| 49 | |||
| 50 | public function deleteMultiple(iterable $keys): bool |
||
| 53 | } |
||
| 54 | } |
||
| 55 |