src/Storefront/Framework/Routing/CachedDomainLoader.php line 36

  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(private readonly AbstractDomainLoader $decorated, private readonly CacheInterface $cache)
  18.     {
  19.     }
  20.     public function getDecorated(): AbstractDomainLoader
  21.     {
  22.         return $this->decorated;
  23.     }
  24.     /**
  25.      * @return array<string, Domain>
  26.      */
  27.     public function load(): array
  28.     {
  29.         $value $this->cache->get(self::CACHE_KEY, fn (ItemInterface $item) => CacheValueCompressor::compress(
  30.             $this->getDecorated()->load()
  31.         ));
  32.         /** @var array<string, Domain> $value */
  33.         $value CacheValueCompressor::uncompress($value);
  34.         return $value;
  35.     }
  36. }