src/Storefront/Theme/CachedResolvedConfigLoader.php line 32

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Theme;
  3. use Shopware\Core\Framework\Adapter\Cache\CacheValueCompressor;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  6. use Symfony\Contracts\Cache\CacheInterface;
  7. use Symfony\Contracts\Cache\ItemInterface;
  8. #[Package('storefront')]
  9. class CachedResolvedConfigLoader extends AbstractResolvedConfigLoader
  10. {
  11.     /**
  12.      * @internal
  13.      */
  14.     public function __construct(private readonly AbstractResolvedConfigLoader $decorated, private readonly CacheInterface $cache)
  15.     {
  16.     }
  17.     public function getDecorated(): AbstractResolvedConfigLoader
  18.     {
  19.         return $this->decorated;
  20.     }
  21.     public function load(string $themeIdSalesChannelContext $context): array
  22.     {
  23.         $name self::buildName($themeId);
  24.         $key md5(implode('-', [$name$context->getSalesChannelId(), $context->getDomainId()]));
  25.         $value $this->cache->get($key, function (ItemInterface $item) use ($name$themeId$context) {
  26.             $config $this->getDecorated()->load($themeId$context);
  27.             $item->tag([$name]);
  28.             return CacheValueCompressor::compress($config);
  29.         });
  30.         return CacheValueCompressor::uncompress($value);
  31.     }
  32.     public static function buildName(string $themeId): string
  33.     {
  34.         return 'theme-config-' $themeId;
  35.     }
  36. }