1 | <?php |
||
2 | namespace Kpicaza\RedisETagCache; |
||
3 | use Kpicaza\ETagCache\ETagCacheInterface; |
||
4 | use Kpicaza\ETagCache\ETagGeneratorInterface; |
||
5 | use Predis\ClientInterface; |
||
6 | |||
7 | /** |
||
8 | * Class RedisETagCache |
||
9 | * @package Kpicaza\RedisETagCache |
||
10 | */ |
||
11 | class RedisETagCache implements ETagCacheInterface |
||
12 | { |
||
13 | protected $client; |
||
14 | protected $generator; |
||
15 | /** |
||
16 | * RedisETagCache constructor. |
||
17 | * @param ETagGeneratorInterface $generator |
||
18 | * @param ClientInterface $client |
||
19 | */ |
||
20 | 5 | public function __construct(ETagGeneratorInterface $generator, ClientInterface $client) |
|
21 | { |
||
22 | 5 | $this->client = $client; |
|
23 | 5 | $this->generator = $generator; |
|
24 | 5 | } |
|
25 | /** |
||
26 | * @param $id |
||
27 | * @param $item |
||
28 | * @return bool |
||
29 | */ |
||
30 | 1 | public function setETag($id, $item) |
|
31 | { |
||
32 | 1 | return (bool) $this->client->set($id, $this->generator->create($item)); |
|
33 | } |
||
34 | /** |
||
35 | * @param $id |
||
36 | * @return mixed |
||
37 | */ |
||
38 | 2 | public function getETag($id) |
|
39 | { |
||
40 | 2 | return $this->client->get($id); |
|
41 | } |
||
42 | } |
||
43 |