Skip to content

Magento 2 – Purge Varnish Cache for specific CMS Block

I have correctly implemented the purges to varnish from Magento, but when I modify a product the changes are reflected when it is not inside a cms block, for example when I see them inside a category they are seen correctly. The problem is when the modified product is inside a cms block, the changes are not reflected.
I have tried to add the tags of the cms blocks with the ids using the Rows.php model, as seen below:

/vendor/magento/module-catalog/Model/Indexer/Product/Category/Action/Rows.php

...
        $this->registerProducts($idsToBeReIndexed);
        $this->registerCategories($affectedCategories);
        $this->registerBlocks($blockIds);
        $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]);
...
    /**
     * Register affected blocks
     *
     * @param array $entityIds
     * @return void
     */
    private function registerBlocks($entityIds)
    {
        $this->cacheContext->registerEntities(Block::CACHE_TAG, $entityIds);
    }
...

But it hasn’t worked, the products that are inside the cms block are still not visible with the modifications