You are here

class StoreCacheContext in Commerce Core 8.2

Defines the StoreCacheContext service, for "per store" caching.

Cache context ID: 'store'.

Hierarchy

Expanded class hierarchy of StoreCacheContext

1 string reference to 'StoreCacheContext'
commerce_store.services.yml in modules/store/commerce_store.services.yml
modules/store/commerce_store.services.yml
1 service uses StoreCacheContext
cache_context.store in modules/store/commerce_store.services.yml
Drupal\commerce_store\Cache\Context\StoreCacheContext

File

modules/store/src/Cache/Context/StoreCacheContext.php, line 14

Namespace

Drupal\commerce_store\Cache\Context
View source
class StoreCacheContext implements CacheContextInterface {

  /**
   * The current store.
   *
   * @var \Drupal\commerce_store\CurrentStoreInterface
   */
  protected $currentStore;

  /**
   * Constructs a new StoreCacheContext class.
   *
   * @param \Drupal\commerce_store\CurrentStoreInterface $current_store
   *   The current store.
   */
  public function __construct(CurrentStoreInterface $current_store) {
    $this->currentStore = $current_store;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return t('Store');
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    $store = $this->currentStore
      ->getStore();
    return $store ? $store
      ->id() : '0';
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
StoreCacheContext::$currentStore protected property The current store.
StoreCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
StoreCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
StoreCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
StoreCacheContext::__construct public function Constructs a new StoreCacheContext class.