MageSmith
Magento_UrlRewrite · Magento 2.4.9

clean_cache_by_tags

Magento 2 event dispatched from Magento_UrlRewrite. Observers bound to this event run whenever the code path that dispatches it executes.

Dispatch location(s)

Every place in Magento 2 core where clean_cache_by_tags is fired. Open the file in your local Magento source to see the event arguments passed alongside the name.

vendor/magento/module-url-rewrite/Model/UrlRewrite.php line 226
vendor/magento/module-catalog/Model/Category.php line 449
vendor/magento/module-catalog/Model/Indexer/Product/Category/Action/Rows.php line 150
vendor/magento/module-catalog/Model/Indexer/Category/Product/Action/Rows.php line 151
vendor/magento/module-catalog/Plugin/Model/Product/Action/UpdateAttributesFlushCache.php line 47
vendor/magento/module-catalog/Plugin/Model/Product/Action/UpdateAttributesFlushCache.php line 60
vendor/magento/module-catalog-rule/Model/Indexer/AbstractIndexer.php line 71
vendor/magento/module-catalog-inventory/Model/Indexer/Stock/CacheCleaner.php line 91
vendor/magento/module-catalog-inventory/Model/Indexer/Stock/CacheCleaner.php line 95
vendor/magento/module-inventory-cache/Model/FlushCacheByCacheTag.php line 61
vendor/magento/module-indexer/Model/Indexer/DeferredCacheCleaner.php line 74
vendor/magento/module-directory-graph-ql/Plugin/Currency.php line 45
vendor/magento/module-configurable-product/Plugin/Model/ResourceModel/Product.php line 145
vendor/magento/framework/Model/AbstractModel.php line 865
vendor/magento/framework/Model/AbstractModel.php line 915

Observer skeleton

Paste into your module's etc/events.xml + create the matching Observer class. Adjust the vendor/module namespace to yours.

1. etc/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="clean_cache_by_tags">
        <observer name="vendor_module_clean_cache_by_tags"
                  instance="Vendor\Module\Observer\CleanCacheByTags"/>
    </event>
</config>

2. Observer class

<?php
declare(strict_types=1);

namespace Vendor\Module\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class CleanCacheByTags implements ObserverInterface
{
    public function execute(Observer $observer): void
    {
        $event = $observer->getEvent();

        // Read whatever payload this event carries. Check the
        // dispatch() call in core to see the exact keys.
        // Example: $product = $event->getProduct();

        // Your observer logic here.
    }
}

Need the full module scaffolded around this observer? Module Generator wires the events.xml, observer class, and module registration for you.

Every Magento dev tool, in one hosted workspace.

Free to sign up. Nothing to install. Drafts, audits, and projects saved across every tool.