Skip to content

Commit 495bfb2

Browse files
Remove cache defaults (#54)
1 parent 8b30fc4 commit 495bfb2

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

src/HttpClient/Builder.php

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use Http\Client\Common\HttpMethodsClient;
1717
use Http\Client\Common\Plugin;
18-
use Http\Client\Common\Plugin\Cache\Generator\CacheKeyGenerator;
1918
use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator;
2019
use Http\Client\Common\Plugin\CachePlugin;
2120
use Http\Client\Common\PluginClientFactory;
@@ -34,13 +33,6 @@
3433
*/
3534
final class Builder
3635
{
37-
/**
38-
* The default cache lifetime of 48 hours.
39-
*
40-
* @var int
41-
*/
42-
const DEFAULT_CACHE_LIFETIME = 172800;
43-
4436
/**
4537
* The object that sends HTTP messages.
4638
*
@@ -171,31 +163,14 @@ public function removePlugin(string $fqcn)
171163
*/
172164
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
173165
{
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+
}
179169

170+
$this->cachePlugin = CachePlugin::clientCache($cachePool, $this->streamFactory, $config);
180171
$this->httpClientModified = true;
181172
}
182173

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-
199174
/**
200175
* Remove the cache plugin.
201176
*

0 commit comments

Comments
 (0)