vendor/shopware/core/Checkout/Cart/CachedRuleLoader.php line 37

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Cart;
  3. use Shopware\Core\Content\Rule\RuleCollection;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Symfony\Contracts\Cache\CacheInterface;
  7. #[Package('checkout')]
  8. class CachedRuleLoader extends AbstractRuleLoader
  9. {
  10.     public const CACHE_KEY 'cart_rules';
  11.     private AbstractRuleLoader $decorated;
  12.     private CacheInterface $cache;
  13.     /**
  14.      * @internal
  15.      */
  16.     public function __construct(AbstractRuleLoader $decoratedCacheInterface $cache)
  17.     {
  18.         $this->decorated $decorated;
  19.         $this->cache $cache;
  20.     }
  21.     public function getDecorated(): AbstractRuleLoader
  22.     {
  23.         return $this->decorated;
  24.     }
  25.     public function load(Context $context): RuleCollection
  26.     {
  27.         return $this->cache->get(self::CACHE_KEY, function () use ($context): RuleCollection {
  28.             return $this->decorated->load($context);
  29.         });
  30.     }
  31. }