php Magento-Framework-App-Cache-TypeListInterface类(方法)实例源码

下面列出了php Magento-Framework-App-Cache-TypeListInterface 类(方法)源码代码实例,从而了解它的用法。

作者:rafaelst    项目:magento   
public function testAfterDelete()
 {
     $this->configMock->expects($this->any())->method('getValue')->willReturnMap([[Theme::XML_PATH_INVALID_CACHES, ScopeInterface::SCOPE_STORE, null, ['block_html' => 1, 'layout' => 1, 'translate' => 1]], [null, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, 'old_value']]);
     $this->cacheTypeListMock->expects($this->exactly(2))->method('invalidate');
     $this->model->setValue('some_value');
     $this->assertSame($this->model, $this->model->afterDelete());
 }

作者:zhangjiacha    项目:magento   
/**
  * Invalidate full page cache
  *
  * @return void
  */
 public function execute()
 {
     if ($this->_config->isEnabled()) {
         $this->_typeList->invalidate('full_page');
     }
     return $this;
 }

作者:pradeep-wagent    项目:magento   
/**
  * @param int $callNumber
  * @param string $oldValue
  * @dataProvider afterSaveDataProvider
  */
 public function testAfterSave($callNumber, $oldValue)
 {
     $this->cacheTypeListMock->expects($this->exactly($callNumber))->method('invalidate');
     $this->configMock->expects($this->any())->method('getValue')->willReturnMap([[Theme::XML_PATH_INVALID_CACHES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, null, ['block_html' => 1, 'layout' => 1, 'translate' => 1]], [null, \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null, $oldValue]]);
     $this->model->setValue('some_value');
     $this->assertInstanceOf(get_class($this->model), $this->model->afterSave());
 }

作者:magefa    项目:module-blo   
/**
  * Invalidate full page and block cache
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_config->isEnabled()) {
         $this->_typeList->invalidate(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER);
     }
     $this->_typeList->invalidate(\Magento\Framework\App\Cache\Type\Block::TYPE_IDENTIFIER);
 }

作者:dineshmaleka    项目:Magento2-Developer-Debug-Too   
/**
  * 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));
     }
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * @param AbstractAction $subject
  * @param AbstractAction $result
  * @return AbstractAction
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterExecute(AbstractAction $subject, AbstractAction $result)
 {
     if ($this->config->isEnabled()) {
         $this->typeList->invalidate('full_page');
     }
     return $result;
 }

作者:pradeep-wagent    项目:magento   
/**
  * Invalidate WebApi cache if needed.
  * 
  * @param \Magento\Framework\App\Config\Value $subject
  * @param \Magento\Framework\App\Config\Value $result
  * @return \Magento\Framework\App\Config\Value
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterAfterSave(\Magento\Framework\App\Config\Value $subject, \Magento\Framework\App\Config\Value $result)
 {
     if ($subject->getPath() == \Magento\WebapiSecurity\Model\Plugin\AnonymousResourceSecurity::XML_ALLOW_INSECURE && $subject->isValueChanged()) {
         $this->cacheTypeList->invalidate(\Magento\Framework\App\Cache\Type\Webapi::TYPE_IDENTIFIER);
     }
     return $result;
 }

作者:Atli    项目:docker-magento   
/**
  * Get array of cache types which require data refresh
  *
  * @return array
  */
 protected function _getCacheTypesForRefresh()
 {
     $output = array();
     foreach ($this->_cacheTypeList->getInvalidated() as $type) {
         $output[] = $type->getCacheType();
     }
     return $output;
 }

作者:pradeep-wagent    项目:magento   
public function testAfterExecuteInvalidate()
 {
     $subject = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\AbstractAction')->disableOriginalConstructor()->getMockForAbstractClass();
     $result = $this->getMockBuilder('Magento\\Catalog\\Model\\Indexer\\Category\\Product\\AbstractAction')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->config->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->typeList->expects($this->once())->method('invalidate')->with('full_page');
     $this->assertEquals($result, $this->execute->afterExecute($subject, $result));
 }

作者:Doabilit    项目:magento2de   
/**
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
  * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
  */
 public function afterSave(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject, \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result)
 {
     if ($this->swatchHelper->isSwatchAttribute($subject)) {
         $this->typeList->invalidate(Block::TYPE_IDENTIFIER);
         $this->typeList->invalidate(Collection::TYPE_IDENTIFIER);
     }
     return $result;
 }

作者:shabbirvividad    项目:magento   
/**
  * @param \Magento\Catalog\Model\Resource\Attribute $subject
  * @param callable $proceed
  * @param \Magento\Framework\Model\AbstractModel $attribute
  * @return mixed
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundSave(\Magento\Catalog\Model\Resource\Attribute $subject, \Closure $proceed, \Magento\Framework\Model\AbstractModel $attribute)
 {
     $result = $proceed($attribute);
     if ($this->config->isEnabled()) {
         $this->typeList->invalidate('full_page');
     }
     return $result;
 }

作者:Doabilit    项目:magento2de   
/**
  * @dataProvider invalidateCacheDataProvider
  * @param bool $cacheState
  */
 public function testExecute($cacheState)
 {
     $this->_configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState));
     if ($cacheState) {
         $this->_typeListMock->expects($this->once())->method('invalidate')->with($this->equalTo('full_page'));
     }
     $this->_model->execute($this->observerMock);
 }

作者:whoopl    项目:magento2-testin   
/**
  * Set status 'invalidate' for blocks and other output caches
  *
  * @return $this
  */
 public function afterSave()
 {
     $types = array_keys($this->_scopeConfig->getValue(self::XML_PATH_INVALID_CACHES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE));
     if ($this->isValueChanged()) {
         $this->_cacheTypeList->invalidate($types);
     }
     return $this;
 }

作者:pradeep-wagent    项目:magento   
/**
  * @dataProvider invalidateCacheDataProvider
  * @param bool $cacheState
  */
 public function testExecuteNoChanged($cacheState)
 {
     $this->configMock->expects($this->once())->method('isEnabled')->will($this->returnValue($cacheState));
     $this->typeListMock->expects($this->never())->method('invalidate');
     if ($cacheState) {
         $this->objectMock->expects($this->once())->method('getIdentities')->will($this->returnValue([]));
     }
     $this->model->execute($this->observerMock);
 }

作者:shabbirvividad    项目:magento   
/**
  * Load data
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         foreach ($this->_cacheTypeList->getTypes() as $type) {
             $this->addItem($type);
         }
         $this->_setIsLoaded(true);
     }
     return $this;
 }

作者:Doabilit    项目:magento2de   
/**
  * Check whether specified cache types exist
  *
  * @param array $types
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _validateTypes(array $types)
 {
     if (empty($types)) {
         return;
     }
     $allTypes = array_keys($this->_cacheTypeList->getTypes());
     $invalidTypes = array_diff($types, $allTypes);
     if (count($invalidTypes) > 0) {
         throw new LocalizedException(__('Specified cache type(s) don\'t exist: %1', join(', ', $invalidTypes)));
     }
 }

作者:shabbirvividad    项目:magento   
/**
  * Invalidate full page cache if content is changed
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->config->isEnabled()) {
         $object = $observer->getEvent()->getObject();
         if ($object instanceof \Magento\Framework\Object\IdentityInterface) {
             if ($object->getIdentities()) {
                 $this->typeList->invalidate('full_page');
             }
         }
     }
 }

作者:kidaa3    项目:magento2-platforms   
public function testAroundSave()
 {
     $subject = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Attribute')->disableOriginalConstructor()->getMock();
     $attribute = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->disableOriginalConstructor()->getMock();
     $self = $this;
     $proceed = function ($object) use($self, $attribute) {
         $self->assertEquals($object, $attribute);
     };
     $this->config->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->typeList->expects($this->once())->method('invalidate')->with('full_page');
     $this->save->aroundSave($subject, $proceed, $attribute);
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * Initialize cache management form
  *
  * @return $this
  */
 public function initForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $fieldset = $form->addFieldset('cache_enable', ['legend' => __('Cache Control')]);
     $fieldset->addField('all_cache', 'select', ['name' => 'all_cache', 'label' => '<strong>' . __('All Cache') . '</strong>', 'value' => 1, 'options' => ['' => __('No change'), 'refresh' => __('Refresh'), 'disable' => __('Disable'), 'enable' => __('Enable')]]);
     foreach ($this->cacheTypeList->getTypeLabels() as $type => $label) {
         $fieldset->addField('enable_' . $type, 'checkbox', ['name' => 'enable[' . $type . ']', 'label' => __($label), 'value' => 1, 'checked' => (int) $this->_cacheState->isEnabled($type)]);
     }
     $this->setForm($form);
     return $this;
 }

作者:pradeep-wagent    项目:magento   
/**
  * Decorate status column values
  *
  * @param string $value
  * @param  \Magento\Framework\Model\AbstractModel $row
  * @param \Magento\Backend\Block\Widget\Grid\Column $column
  * @param bool $isExport
  * @return string
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function decorateStatus($value, $row, $column, $isExport)
 {
     $invalidedTypes = $this->_cacheTypeList->getInvalidated();
     if (isset($invalidedTypes[$row->getId()])) {
         $cell = '<span class="grid-severity-minor"><span>' . __('Invalidated') . '</span></span>';
     } else {
         if ($row->getStatus()) {
             $cell = '<span class="grid-severity-notice"><span>' . $value . '</span></span>';
         } else {
             $cell = '<span class="grid-severity-critical"><span>' . $value . '</span></span>';
         }
     }
     return $cell;
 }


问题


面经


文章

微信
公众号

扫码关注公众号