I want to call my observer after the adminhtml_cache_refresh_type
event and specifically after full_page
This method does not work, is there a way to do this in observer?
<event name="adminhtml_cache_refresh_type" type="full_page">
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI want to call my observer after the adminhtml_cache_refresh_type
event and specifically after full_page
This method does not work, is there a way to do this in observer?
<event name="adminhtml_cache_refresh_type" type="full_page">
yes theres a way to do this in observer:
make a file called events.xml in etc folder:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="adminhtml_cache_refresh_type">
<observer name="RefreshCacheType" instance="Mageplaza\yourmodule\Observer\RefreshCacheType" />
</event>
</config>
in your observer file RefreshCacheType.php:
<?php
namespace Mageplaza\yourmodule\Observer;
use Magento\Framework\App\PageCache\Version;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Cache\Frontend\Pool;
protected $cacheTypeList;
protected $cacheFrontendPool;
class RefreshCacheType implements \Magento\Framework\Event\ObserverInterface
{
protected $orderFactory;
public function __construct(
TypeListInterface $cacheTypeList,
Pool $cacheFrontendPool
){
$this->cacheTypeList = $cacheTypeList;
$this->cacheFrontendPool = $cacheFrontendPool;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$_types = [
'config',
'layout',
'block_html',
'collections',
'reflection',
'db_ddl',
'eav',
'config_integration',
'config_integration_api',
'full_page',
'translate',
'config_webservice'
];
foreach ($_types as $type) {
$this->cacheTypeList->cleanType($type);
}
foreach ($this->cacheFrontendPool as $cacheFrontend) {
$cacheFrontend->getBackend()->clean();
}
}
}