Menu Close
    Start a Project Request quote Reading list Switch to dark mode

    How to clean and flush cache programmatically in magento2

    How to clean and flush cache programmatically in magento2 – Having issue with cache clear programmatically in magento2, then no need to worry about this . The solution is here, you can easily add this cache clean/flush code to your project by following just some easy steps-

    1. Define constructor – pass Magento\Framework\App\Cache\TypeListInterface and Magento\Framework\App\Cache\Frontend\Pool to your file’s constructor as defined below :

    2. Now add following code to the method where you want clear/flush cache

    So in this way you can clean and flush cache in magento2 . Hope this blog will help you.

    . . .

    Comments (2)

    Add Your Comment

  • Monika Tadvi
    Thank you. This code is working for me.
  • Mitch Thompson
    Shouldn’t you use generated factories and not the actual objects?

    public function __construct(
    MagentoFrameworkAppCacheManagerFactory $cacheManagerFactory)
    $this->cacheManagerFactory = $cacheManagerFactory;

    public function clearCache() {
    $cacheManager = $this->cacheManagerFactory->create();
    $types = $cacheManager->getAvailableTypes();

  • Back to Top
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again