diff --git a/src/Collection.php b/src/Collection.php index 600017c5c..c2429e5d5 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -93,6 +93,7 @@ use loophp\collection\Transformation\Transform; use loophp\collection\Transformation\Truthy; use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use function is_callable; use function is_resource; @@ -246,7 +247,7 @@ public function associate( public function cache(?CacheItemPoolInterface $cache = null): CollectionInterface { - return $this->run(new Cache($cache)); + return $this->run(new Cache($cache ?? new ArrayAdapter())); } public function chunk(int ...$size): CollectionInterface diff --git a/src/Operation/Cache.php b/src/Operation/Cache.php index 1b7ef2dbc..43c6a1c69 100644 --- a/src/Operation/Cache.php +++ b/src/Operation/Cache.php @@ -10,7 +10,6 @@ use loophp\collection\Contract\Operation; use loophp\collection\Iterator\CacheIterator; use Psr\Cache\CacheItemPoolInterface; -use Symfony\Component\Cache\Adapter\ArrayAdapter; /** * @psalm-template TKey @@ -19,9 +18,9 @@ */ final class Cache extends AbstractOperation implements Operation { - public function __construct(?CacheItemPoolInterface $cache = null) + public function __construct(CacheItemPoolInterface $cache) { - $this->storage['cache'] = $cache ?? new ArrayAdapter(); + $this->storage['cache'] = $cache; } public function __invoke(): Closure