1

I am creating a module where the customer can design a product(saved programmatically), so each time he designs the product a new product image which is generated. But it is not updated in the category view page, but it is updated on the product view page. Upon research, I found that the images are loaded from the cache in the category page. Is there a way to overcome this problem?

As the user is re-designing the product( done programmatically in a module), it is impractical to clear cache or re-index from the admin side each time.

0

Go to System > Cache Management and scroll to the bottom of the page. Then click the Flush Catalog Images Cache button and the clear the other caches.

Or

You can run re-indexing : php bin/magento indexer:reindex

Hope this will help you! Thanks.

  • Hi, thanks for the reply. I read about this, but as the user is re-designing the product( done programmatically in a module), it is impractical to clear cache or re-index from the admin side each time. – Sidharth Satheesh Jul 11 at 3:27
0

You can try below code For clearing cache and Re-indexing

You can call these functions flushCache(), doReIndex() wherever user is re-designing the product in a your module.

<?php

namespace Vendor\Module\Block;

use Magento\Framework\App\PageCache\Version;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\App\Cache\Frontend\Pool;

class Operations
{
    protected $cacheTypeList;
    protected $cacheFrontendPool;
    protected $processor;

    public function __construct(
        TypeListInterface $cacheTypeList,
        Pool $cacheFrontendPool,
        \Magento\Indexer\Model\Processor $processor
    ) {
        $this->cacheTypeList = $cacheTypeList;
        $this->cacheFrontendPool = $cacheFrontendPool;
        $this->processor = $processor;
    }

    public function flushCache()
    {
        // Get all types of caches
        $_types = array_keys($this->cacheTypeList->getTypes());

        /*
         * It will return cache list array('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();
        }
    }

    public function doReIndex()
    {
        /* Regenerate indexes for all indexers */
        $this->processor->reindexAll();

        /* Regenerate indexes for all invalid indexers */
        $this->processor->reindexAllInvalid()
    }
}

To flush the product image cache: From the Cache Storage Management page, under Additional Cache Management, click Flush Catalog Images Cache to clear pre-generated product image files.

The Image cache was cleaned message appears at the top of the workspace.

Clear the cache of your browser.

Check Magento Docs

  • Hi, Thanks for your reply @MohitRane , Is there an option to flush the Magento2 Image cache? – Sidharth Satheesh Jul 11 at 6:28
  • Please check updated answer – Mohit Rane Jul 11 at 8:01
  • accept the answer if it's solved your issue, so it could help others – Mohit Rane Jul 11 at 8:11
  • No it didnt work – Sidharth Satheesh Jul 11 at 10:59
  • I've updated the code, please check now. – Mohit Rane Jul 11 at 11:01

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.