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.
Be the first to comment.