class StoreCacheContext in Commerce Core 8.2
Defines the StoreCacheContext service, for "per store" caching.
Cache context ID: 'store'.
Hierarchy
- class \Drupal\commerce_store\Cache\Context\StoreCacheContext implements CacheContextInterface
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
File
- modules/
store/ src/ Cache/ Context/ StoreCacheContext.php, line 14
Namespace
Drupal\commerce_store\Cache\ContextView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StoreCacheContext:: |
protected | property | The current store. | |
StoreCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
StoreCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
StoreCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
StoreCacheContext:: |
public | function | Constructs a new StoreCacheContext class. |