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

  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. /**
  8.  * @internal Depend on the AbstractRuleLoader which is the definition of public API for this scope
  9.  */
  10. #[Package('checkout')]
  11. class CachedRuleLoader extends AbstractRuleLoader
  12. {
  13.     final public const CACHE_KEY 'cart_rules';
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(private readonly AbstractRuleLoader $decorated, private readonly CacheInterface $cache)
  18.     {
  19.     }
  20.     public function getDecorated(): AbstractRuleLoader
  21.     {
  22.         return $this->decorated;
  23.     }
  24.     public function load(Context $context): RuleCollection
  25.     {
  26.         return $this->cache->get(self::CACHE_KEY, fn (): RuleCollection => $this->decorated->load($context));
  27.     }
  28. }