| Total Complexity | 11 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class FileCache implements CacheInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $cacheFilePath; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var integer |
||
| 18 | */ |
||
| 19 | protected $ttl; |
||
| 20 | |||
| 21 | public function __construct(string $cacheFilePath, int $ttl) |
||
| 22 | { |
||
| 23 | $this->cacheFilePath = $cacheFilePath; |
||
| 24 | $this->ttl = $ttl; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function get($key, $default = null) |
||
| 28 | { |
||
| 29 | return ($this->has($key)) ? file_get_contents($this->cacheFilePath) : $default; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function set($key, $value, $ttl = null): bool |
||
| 33 | { |
||
| 34 | return (bool) file_put_contents($this->cacheFilePath, $value); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function has($key): bool |
||
| 38 | { |
||
| 39 | return file_exists($this->cacheFilePath) && time() - filemtime($this->cacheFilePath) < $this->ttl; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function delete($key): bool |
||
| 43 | { |
||
| 44 | return unlink($this->cacheFilePath); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function clear(): bool |
||
| 48 | { |
||
| 49 | return $this->delete($this->cacheFilePath); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getMultiple($keys, $default = null): iterable |
||
| 55 | } |
||
| 56 | |||
| 57 | public function setMultiple($values, $ttl = null): bool |
||
| 58 | { |
||
| 59 | return false; |
||
| 60 | } |
||
| 61 | |||
| 62 | public function deleteMultiple($keys): bool |
||
| 65 | } |
||
| 66 | } |
||
| 67 |