Back to Top

Custom Extension Cache Management with Fastly in adobe commerce cloud

Updated 20 February 2024

Magento2 cloud edition(Adobe commerce) require Fastly cache with varnish for provide fast caching and a CDN. For more details about fastly for cloud for adobe commerce development please check https://devdocs.magento.com/cloud/cdn/configure-fastly.html .

So as a developer many times we need to flush cache using code in our custom extensions, and for that we need to write cache flush code, but in magento2 cloud edition, to work with fastly, we need to send purge request to fastly and for that fastly is using ‘adminhtml_cache_flush_all’ event observer to send purge request.

So please check the code for flushing cache to compatible with fastly-

/**
 * @var \Magento\Framework\App\Cache\Manager
 */
protected $cacheManager;

/**
 * @var \Magento\Framework\Event\ManagerInterface
 */
protected $eventManager;
 
public function __construct(
    \Magento\Framework\App\Cache\Manager $cacheManager,
    \Magento\Framework\Event\ManagerInterface $eventManager
){
      $this->cacheManager = $cacheManager;
      $this->eventManager = $eventManager;
}
 
public function cacheFlush()
{
     $availableTypes = $this->cacheManager->getAvailableTypes();
     $this->eventManager->dispatch('adminhtml_cache_flush_all');
     $this->cacheManager->flush($availableTypes);
}

Now you are ready to go, your extension is compatible with Fastly.

you can get more magento2 (Adobe Commerce) articles here.

Start your headless eCommerce
now.
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home