1 | <?php |
||
2 | /** |
||
3 | * Storage API |
||
4 | * User: moyo |
||
5 | * Date: 24/10/2017 |
||
6 | * Time: 12:13 PM |
||
7 | */ |
||
8 | |||
9 | namespace Carno\Cache\Chips; |
||
10 | |||
11 | use Carno\Cache\Contracts\Storing; |
||
12 | |||
13 | trait Storage |
||
14 | { |
||
15 | /** |
||
16 | * @var Storing |
||
17 | */ |
||
18 | private $backend = null; |
||
19 | |||
20 | /** |
||
21 | * @param string $key |
||
22 | * @return bool |
||
23 | */ |
||
24 | final public function has(string $key) |
||
25 | { |
||
26 | return yield $this->backend->has($this->key($key)); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param string $key |
||
31 | * @return mixed|null |
||
32 | */ |
||
33 | final public function read(string $key) |
||
34 | { |
||
35 | return (false !== $got = yield $this->backend->read($this->key($key))) ? $got : null; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param string $key |
||
40 | * @param mixed $data |
||
41 | * @param int $ttl |
||
42 | * @return bool |
||
43 | */ |
||
44 | final public function write(string $key, $data, int $ttl = null) |
||
45 | { |
||
46 | return yield $this->backend->write($this->key($key), $data, $ttl ?? $this->ttl); |
||
0 ignored issues
–
show
|
|||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $key |
||
51 | * @return bool |
||
52 | */ |
||
53 | final public function remove(string $key) |
||
54 | { |
||
55 | return yield $this->backend->remove($this->key($key)); |
||
0 ignored issues
–
show
|
|||
56 | } |
||
57 | } |
||
58 |