1 | <?php |
||
9 | class ResponseCacheRepository |
||
10 | { |
||
11 | protected Repository $cache; |
||
|
|||
12 | |||
13 | protected Serializer $responseSerializer; |
||
14 | |||
15 | public function __construct(Serializer $responseSerializer, Repository $cache) |
||
16 | { |
||
17 | $this->cache = $cache; |
||
18 | |||
19 | $this->responseSerializer = $responseSerializer; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param string $key |
||
24 | * @param \Symfony\Component\HttpFoundation\Response $response |
||
25 | * @param \DateTime|int $seconds |
||
26 | */ |
||
27 | public function put(string $key, $response, $seconds) |
||
28 | { |
||
29 | $this->cache->put($key, $this->responseSerializer->serialize($response), is_numeric($seconds) ? now()->addSeconds($seconds) : $seconds); |
||
30 | } |
||
31 | |||
32 | public function has(string $key): bool |
||
33 | { |
||
34 | return $this->cache->has($key); |
||
35 | } |
||
36 | |||
37 | public function get(string $key): Response |
||
38 | { |
||
39 | return $this->responseSerializer->unserialize($this->cache->get($key)); |
||
40 | } |
||
41 | |||
42 | public function clear() |
||
43 | { |
||
44 | $this->cache->clear(); |
||
45 | } |
||
46 | |||
47 | public function forget(string $key): bool |
||
48 | { |
||
49 | return $this->cache->forget($key); |
||
50 | } |
||
51 | |||
52 | public function tags(array $tags): self |
||
53 | { |
||
54 | return new self($this->responseSerializer, $this->cache->tags($tags)); |
||
55 | } |
||
56 | } |
||
57 |