0

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">
1

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();
    }



    }
}
| improve this answer | |
  • This decision does not mean what I mean. – Alice Jul 13 at 11:43
  • you cannot use <event name="adminhtml_cache_refresh_type" type="full_page"> like this especially the type= "full_page", you can make an observer on the adminhtml_cache_refresh_type event and can do what you need in the observer. – nihal malik Jul 13 at 11:57
0

The syntax type="full_page" is wrong attribute.You can not use like this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.