PHP code example of blackbird / magento-2-clean-product-image-cache

1. Go to this page and download the library: Download blackbird/magento-2-clean-product-image-cache library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blackbird / magento-2-clean-product-image-cache example snippets


class MyCleanCacheStrategy implements CleanCacheStrategyInterface
{
     /**
     * {@inheritDoc}
     */
    public function clean(ProductInterface $product): void
    {
        //Do what you need to do
    }
}

class AfterCleanMagentoImageCache implements ObserverInterface
{
     /**
     * {@inheritDoc}
     */
    public function execute(Observer $observer): void
    {
        //Get absolute path off all cached images for the cleaned product
        $paths = $observer->getPaths();
        //Do what you need to do
    }
}

php bin/magento setup:upgrade
xml
...
    <type name="Blackbird\CleanProductImageCache\Model\Service\CleanCacheStrategyPool">
        <arguments>
            <argument name="cleanCacheStrategies" xsi:type="array">
                <item name="my_clean" xsi:type="array">
                    <item name="class" xsi:type="object">Vendor\Module\Model\Service\MyCleanCacheStrategy</item>
                    <item name="sortOrder" xsi:type="number">10</item>
                    <item name="enabled" xsi:type="boolean">true</item>
                </item>
            </argument>
        </arguments>
    </type>
...