Magento 2: Clean Fastly or Varnish Cache by Cache Tag Programmatically

This article shows how you can clean Fastly Cache or Varnish Cache by cache tags in Magento. Fastly has an observer that listens to the event clean_cache_by_tags. vendor/fastly/magento2/etc/events.xml (github) <event name="clean_cache_by_tags"> <observer name="flush_fastly_cdn" instance="Fastly\Cdn\Observer\InvalidateVarnishObserver"/> </event> The \Fastly\Cdn\Observer\InvalidateVarnishObserver class further calls the \Fastly\Cdn\Model\PurgeCache::sendPurgeRequest($pattern) method which finally cleans the Fastly Cache utilizing \Fastly\Cdn\Model\Api. Magento’s Cache_Invalidate module has … Read more

Magento 2: Clean Cache by Cache Tags Programmatically

This article shows how you can clean cache by cache tags in Magento. use Magento\Framework\App\CacheInterface; class YourClassName { /** * @var CacheInterface */ protected $cache; /** … * @param CacheInterface $cache */ public function __construct( … CacheInterface $cache ) { … $this->cache = $cache; } /** * Clean Cache by Cache Tag * * @param … Read more

Magento 2: Enable/Disable Cache Programmatically

This article shows how you can enable or disable Magento Cache Programmatically. For this purpose, we will be using \Magento\Framework\App\Cache\Manager class. use Magento\Framework\App\Cache\Manager as CacheManager; class YourClassName { /** * @var CacheManager */ protected $cacheManager; /** … * @param CacheManager $cacheManager */ public function __construct( … CacheManager $cacheManager ) { … $this->cacheManager = $cacheManager; } … Read more

Magento 2: Get, Clean and Flush Cache Programmatically

This article shows how you can get the list of all Cache Types in Magento and how you can clean and flush those Cache Types in Magento. Cache Types in Magento Magento has the following cache types: Configuration (config) Commerce collects configuration from all modules, merges it, and saves the merged result to the cache. … Read more

Magento 2: Enable/Disable/Clear Cache (Clean/Flush) via Command Line

This article shows how you can clear Magento 2 cache using command line. In my previous article, I have listed out all the command line tools that can be used in Magento 2. This article specifically shows about commands to clear Magento 2 cache. Check Cache Status First of all, let’s see what is the … Read more