I am creating a module that clears invalidated cache,

I am trying to get invalidated cache types in controller, so i can clear cache for only cache types which are invalidated.

How to invalidated cache types in controller ?

1 Answer 1


Check out how Magento does it when rendering the caches in vendor/magento/module-backend/Block/Cache/Grid/Column/Statuses.php.

Basically, it injects the \Magento\Framework\App\Cache\TypeListInterface class in constructor and it retrieves the list of invalidated caches by calling the method of the concrete class vendor/magento/framework/App/Cache/TypeList.php which implements the method:

  • i am assuming, that using this class & calling this getInvalidated method i will get the invalidated cache types in controller. Mar 2, 2021 at 10:55
  • 1
    yes, that's right. you should get the right results. I just edited my answer and added the concrete class reference also.
    – Diana
    Mar 2, 2021 at 10:56
  • $output = []; foreach ($this->_cacheTypeList->getInvalidated() as $type) { $output[] = $type->getCacheType(); } return $output; Mar 2, 2021 at 10:56
  • Thankyou for the answer Mar 2, 2021 at 10:56
  • you're welcome! consider marking the answer as solution so others can see it too. cheers!
    – Diana
    Mar 2, 2021 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.