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

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 Symfony\Contracts\Cache\CacheInterface;
  6. class CachedRuleLoader extends AbstractRuleLoader
  7. {
  8.     public const CACHE_KEY 'cart_rules';
  9.     private AbstractRuleLoader $decorated;
  10.     private CacheInterface $cache;
  11.     /**
  12.      * @internal
  13.      */
  14.     public function __construct(AbstractRuleLoader $decoratedCacheInterface $cache)
  15.     {
  16.         $this->decorated $decorated;
  17.         $this->cache $cache;
  18.     }
  19.     public function getDecorated(): AbstractRuleLoader
  20.     {
  21.         return $this->decorated;
  22.     }
  23.     public function load(Context $context): RuleCollection
  24.     {
  25.         return $this->cache->get(self::CACHE_KEY, function () use ($context): RuleCollection {
  26.             return $this->decorated->load($context);
  27.         });
  28.     }
  29. }