1 | <?php |
||
20 | class GreedyCacheStrategy extends PrivateCacheStrategy |
||
21 | { |
||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $ttl; |
||
26 | |||
27 | /** |
||
28 | * @var KeyValueHttpHeader |
||
29 | */ |
||
30 | private $varyHeaders; |
||
31 | |||
32 | 8 | public function __construct(CacheStorageInterface $cache = null, $ttl, KeyValueHttpHeader $varyHeaders = null) |
|
38 | |||
39 | 7 | protected function getCacheKey(RequestInterface $request, KeyValueHttpHeader $varyHeaders = null) |
|
60 | |||
61 | 7 | public function cache(RequestInterface $request, ResponseInterface $response) |
|
80 | |||
81 | 7 | protected function getCacheObject(RequestInterface $request, ResponseInterface $response) |
|
82 | { |
||
83 | 7 | if (!array_key_exists($response->getStatusCode(), $this->statusAccepted)) { |
|
84 | // Don't cache it |
||
85 | 1 | return null; |
|
86 | } |
||
87 | |||
88 | 6 | if (null !== $this->varyHeaders && $this->varyHeaders->has('*')) { |
|
89 | // This will never match with a request |
||
90 | return; |
||
91 | } |
||
92 | |||
93 | 6 | $response = $response->withoutHeader('Etag')->withoutHeader('Last-Modified'); |
|
94 | 6 | return new CacheEntry($request, $response, new \DateTime(sprintf('+%d seconds', $this->ttl))); |
|
95 | } |
||
96 | |||
97 | 7 | public function fetch(RequestInterface $request) |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function delete(RequestInterface $request) |
||
110 | } |
||
111 |