1 | <?php |
||
8 | class Cache |
||
9 | { |
||
10 | private $converter; |
||
11 | |||
12 | 44 | public function __construct(Converter $converter) |
|
21 | |||
22 | private $cache = []; |
||
23 | |||
24 | 44 | public function exists($key) |
|
25 | { |
||
26 | 44 | if (array_key_exists($key, $this->cache)) { |
|
27 | 4 | return $this->cache[$key]['expire'] > Carbon::now()->getTimestamp(); |
|
28 | } |
||
29 | 44 | $filename = '.cache/'.$key; |
|
30 | 44 | if (file_exists($filename)) { |
|
31 | 2 | if (!array_key_exists($key, $this->cache)) { |
|
32 | 2 | $this->cache[$key] = include $filename; |
|
33 | } |
||
34 | 2 | return $this->cache[$key]['expire'] > Carbon::now()->getTimestamp(); |
|
35 | } |
||
36 | 44 | } |
|
37 | |||
38 | 4 | public function get($key) |
|
44 | |||
45 | 3 | public function set($key, $value) |
|
57 | |||
58 | 44 | public function wrap($key, $callback) |
|
78 | } |
||
79 |
If you suppress an error, we recommend checking for the error condition explicitly: