1

It is not working in .phtml template

                $types = array('full_page');
                foreach ($types as $type) {
                    $cacheTypeList->cleanType($type);
                }
                foreach ($cacheFrontendPool as $cacheFrontend) {
                    $cacheFrontend->getBackend()->clean();
                }
0

Try the below code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
try{
    $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface');
    $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
    $types = array('full_page');
    foreach ($types as $type) {
        $_cacheTypeList->cleanType($type);
    }is
    foreach ($_cacheFrontendPool as $cacheFrontend) {
        $cacheFrontend->getBackend()->clean();
    }
}catch(Exception $e){
    echo $msg = 'Error : '.$e->getMessage();die();
}
  • tried this way, its not working only in templates – Vamsi Jul 12 '18 at 14:49
  • Its a working code. It's working for me. – Sukumar Gorai Jul 12 '18 at 14:57
  • it is working in blocks/controllers but not in .phtml file – Vamsi Jul 12 '18 at 15:06
  • Did you use object manager? which I have mentioned in my answer? – Sukumar Gorai Jul 12 '18 at 15:18
  • Used $objectmanager but it’s not working in template – Vamsi Jul 12 '18 at 15:20

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.