vendor/shopware/storefront/Framework/Routing/CachedDomainLoader.php line 39

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Framework\Routing;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Symfony\Contracts\Cache\CacheInterface;
  6. use Symfony\Contracts\Cache\ItemInterface;
  7. /**
  8.  * @phpstan-import-type Domain from AbstractDomainLoader
  9.  */
  10. #[Package('storefront')]
  11. class CachedDomainLoader extends AbstractDomainLoader
  12. {
  13.     final public const CACHE_KEY 'routing-domains';
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(
  18.         private readonly AbstractDomainLoader $decorated,
  19.         private readonly CacheInterface $cache
  20.     ) {
  21.     }
  22.     public function getDecorated(): AbstractDomainLoader
  23.     {
  24.         return $this->decorated;
  25.     }
  26.     /**
  27.      * @return array<string, Domain>
  28.      */
  29.     public function load(): array
  30.     {
  31.         $value $this->cache->get(self::CACHE_KEY, fn (ItemInterface $item) => CacheValueCompressor::compress(
  32.             $this->getDecorated()->load()
  33.         ));
  34.         /** @var array<string, Domain> $value */
  35.         $value CacheValueCompressor::uncompress($value);
  36.         return $value;
  37.     }
  38. }