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