/**
  * @return bool
  */
 private function isAttributeCacheEnabled()
 {
     if ($this->isAttributeCacheEnabled === null) {
         $this->isAttributeCacheEnabled = $this->state->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
     }
     return $this->isAttributeCacheEnabled;
 }
 /**
  * Toggle cache
  *
  */
 public function execute()
 {
     $allTypes = array_keys($this->_cacheTypeList->getTypes());
     $updatedTypes = 0;
     $disable = true;
     $enable = true;
     foreach ($allTypes as $code) {
         if ($this->_cacheState->isEnabled($code) && $disable) {
             $this->_cacheState->setEnabled($code, false);
             $updatedTypes++;
             $enable = false;
         }
         if (!$this->_cacheState->isEnabled($code) && $enable) {
             $this->_cacheState->setEnabled($code, true);
             $updatedTypes++;
             $disable = false;
         }
         if ($disable) {
             $this->_cacheTypeList->cleanType($code);
         }
     }
     if ($updatedTypes > 0) {
         $this->_cacheState->persist();
         $this->messageManager->addSuccess(__("%1 cache type(s) disabled.", $updatedTypes));
     }
 }
Beispiel #3
0
 /**
  * Check EAV cache availability
  *
  * @return bool
  */
 public function isCacheEnabled()
 {
     if ($this->_isCacheEnabled === null) {
         $this->_isCacheEnabled = $this->_cacheState->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
     }
     return $this->_isCacheEnabled;
 }
Beispiel #4
0
 /**
  * Disable some cache types in VDE mode
  *
  * @return void
  */
 protected function _disableCache()
 {
     foreach ($this->_dataHelper->getDisabledCacheTypes() as $cacheCode) {
         if ($this->_cacheState->isEnabled($cacheCode)) {
             $this->_cacheState->setEnabled($cacheCode, false);
         }
     }
 }
 /**
  * Updates cache status for the requested types
  *
  * @param string[] $types
  * @param bool $isEnabled
  * @return array List of types with changed status
  */
 public function setEnabled(array $types, $isEnabled)
 {
     $changedStatusTypes = [];
     $isUpdated = false;
     foreach ($types as $type) {
         if ($this->cacheState->isEnabled($type) === $isEnabled) {
             // no need to poke it, if is not going to change
             continue;
         }
         $this->cacheState->setEnabled($type, $isEnabled);
         $isUpdated = true;
         $changedStatusTypes[] = $type;
     }
     if ($isUpdated) {
         $this->cacheState->persist();
     }
     return $changedStatusTypes;
 }
 /**
  * Save block content to cache storage
  *
  * @param string $data
  * @return $this
  */
 protected function _saveCache($data)
 {
     if ($this->getCacheLifetime() === null || !$this->_cacheState->isEnabled(self::CACHE_GROUP)) {
         return false;
     }
     $cacheKey = $this->getCacheKey();
     $data = str_replace($this->_sidResolver->getSessionIdQueryParam($this->_session) . '=' . $this->_session->getSessionId(), $this->_getSidPlaceholder($cacheKey), $data);
     $this->_cache->save($data, $cacheKey, $this->getCacheTags(), $this->getCacheLifetime());
     return $this;
 }
Beispiel #7
0
 /**
  * Whether a cache type is enabled at the moment or not
  *
  * @return bool
  */
 protected function _isEnabled()
 {
     return $this->_cacheState->isEnabled($this->_identifier);
 }
Beispiel #8
0
 /**
  * @param \Magento\Framework\App\CacheInterface $cache
  * @param \Magento\Framework\App\Cache\StateInterface $cacheState
  */
 public function __construct(\Magento\Framework\App\CacheInterface $cache, \Magento\Framework\App\Cache\StateInterface $cacheState)
 {
     $this->cache = $cache;
     $this->isCacheEnabled = $cacheState->isEnabled(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER);
 }
Beispiel #9
0
 /**
  * Whether a cache type is enabled in Cache Management Grid
  *
  * @return bool
  * @api
  */
 public function isEnabled()
 {
     return $this->_cacheState->isEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER);
 }
 /**
  * @param $block
  * @return bool
  */
 protected function getCacheState($block)
 {
     return $this->_cacheState->isEnabled($block::CACHE_GROUP);
 }