/** * 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)); } }
/** * 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; }
/** * @return $this */ public function finish() { $this->_setAppInstalled(); $this->_refreshConfig(); /* Enable all cache types */ foreach (array_keys($this->_cacheTypeList->getTypes()) as $cacheTypeCode) { $this->_cacheState->setEnabled($cacheTypeCode, true); } $this->_cacheState->persist(); return $this; }
/** * Whether a cache type is enabled */ public function testIsEnabled() { $this->_cacheState->setEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER, true); $this->_cacheState->expects($this->once())->method('isEnabled')->with(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER)->will($this->returnValue(true)); $this->_model->isEnabled(); }