|
15 | 15 |
|
16 | 16 | use Http\Client\Common\HttpMethodsClient;
|
17 | 17 | use Http\Client\Common\Plugin;
|
18 |
| -use Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator; |
19 | 18 | use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator;
|
20 | 19 | use Http\Client\Common\Plugin\CachePlugin;
|
21 | 20 | use Http\Client\Common\PluginClientFactory;
|
|
34 | 33 | */
|
35 | 34 | final class Builder
|
36 | 35 | {
|
37 |
| - /** |
38 |
| - * The default cache lifetime of 48 hours. |
39 |
| - * |
40 |
| - * @var int |
41 |
| - */ |
42 |
| - const DEFAULT_CACHE_LIFETIME = 172800; |
43 |
| - |
44 | 36 | /**
|
45 | 37 | * The object that sends HTTP messages.
|
46 | 38 | *
|
@@ -171,31 +163,14 @@ public function removePlugin(string $fqcn)
|
171 | 163 | */
|
172 | 164 | public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
|
173 | 165 | {
|
174 |
| - $this->setCachePlugin( |
175 |
| - $cachePool, |
176 |
| - $config['generator'] ?? new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept', 'Content-type']), |
177 |
| - $config['lifetime'] ?? self::DEFAULT_CACHE_LIFETIME |
178 |
| - ); |
| 166 | + if (!isset($config['cache_key_generator'])) { |
| 167 | + $config['cache_key_generator'] = new HeaderCacheKeyGenerator(['Authorization', 'Cookie', 'Accept', 'Content-type']); |
| 168 | + } |
179 | 169 |
|
| 170 | + $this->cachePlugin = CachePlugin::clientCache($cachePool, $this->streamFactory, $config); |
180 | 171 | $this->httpClientModified = true;
|
181 | 172 | }
|
182 | 173 |
|
183 |
| - /** |
184 |
| - * Add a cache plugin to cache responses locally. |
185 |
| - * |
186 |
| - * @param \Psr\Cache\CacheItemPoolInterface $cachePool |
187 |
| - * @param \Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator $generator |
188 |
| - * @param int $lifetime |
189 |
| - * |
190 |
| - * @return void |
191 |
| - */ |
192 |
| - private function setCachePlugin(CacheItemPoolInterface $cachePool, CacheKeyGenerator $generator, int $lifetime) |
193 |
| - { |
194 |
| - $options = ['cache_lifetime' => $lifetime, 'cache_key_generator' => $generator]; |
195 |
| - |
196 |
| - $this->cachePlugin = CachePlugin::clientCache($cachePool, $this->streamFactory, $options); |
197 |
| - } |
198 |
| - |
199 | 174 | /**
|
200 | 175 | * Remove the cache plugin.
|
201 | 176 | *
|
|
0 commit comments