To add to denish's answer, you could write a little php script and place it into your magento root folder:

$command = 'php bin/magento cache:clean && php bin/magento cache:flush';
echo '<pre>' . shell_exec($command) . '</pre>';

This code place to which folder and what file in root directory, When I run my page in frontend : https://www.atomicgolf.shop/contact-list

How could I do for this?

  • If i understand right you want to clear the cache when someone visits a front end page? Cache is what is keeping your website fast. Aug 7 '17 at 5:25
  • yes, I want clear cache by this command in side code. But It has 3 ways to clear. I have done with it inside my code. This link : URL : magento.stackexchange.com/questions/101395/… Aug 8 '17 at 3:41
    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/app/bootstrap.php';
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();

    /* Code to clean cache [ php bin/magento:cache:clean ] */
            $_cacheTypeList = $objectManager->create('Magento\Framework\App\Cache\TypeListInterface');
            $_cacheFrontendPool = $objectManager->create('Magento\Framework\App\Cache\Frontend\Pool');
            $types = array('config','layout','block_html','collections','reflection','db_ddl','eav','config_integration','config_integration_api','full_page','translate','config_webservice');
            foreach ($types as $type) {
            foreach ($_cacheFrontendPool as $cacheFrontend) {
        }catch(Exception $e){
            echo $msg = 'Error during cache clean: '.$e->getMessage();die();
  • Welcome to MSE and Please elaborate your answer
    – Jarnail S
    Jan 28 '19 at 13:52

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.